Scenario: When uploaded a document, expecting a linkfield to show the document to download.
Problem:
When Document is uploaded an error below is thrown. foreach code is below. Please advise what is the issue and how to fix it. Used document function to retrieve name of document as label for link field.
a!fileUploadField( label: "Upload New Documents here", labelPosition: "ABOVE", helptooltip: "Upload any project related documents here or download any uploaded documents through the below links.", value: ri!NSARequest.Forms.AdditionalDocuments, saveInto: a!save(ri!NSARequest.Forms.AdditionalDocuments, append(ri!NSARequest.Forms.AdditionalDocuments, save!value)), target: cons!NSA_Documents_Cons, showWhen: ri!readonly = false, validations: {} ),
a!linkField( label: "Documents Uploaded", links: { a!documentDownloadLink( label: ri!NSARequest.Forms.PartABForm.Name, document: todocument(ri!NSARequest.Forms.PartABForm.DocumentId), showWhen: not(isnull(ri!NSARequest.Forms.PartABForm.DocumentId)) ), a!documentDownloadLink( label: ri!NSARequest.Forms.PartCForm.Name, document: todocument(ri!NSARequest.Forms.PartCForm.DocumentId), showWhen: not(isnull(ri!NSARequest.Forms.PartCForm.DocumentId)) ), a!documentDownloadLink( label: ri!NSARequest.Forms.PartDForm.Name, document: todocument(ri!NSARequest.Forms.PartDForm.DocumentId), showWhen: not(isnull(ri!NSARequest.Forms.PartDForm.DocumentId)) ), a!forEach( items: ri!NSARequest.Forms.AdditionalDocuments, expression: a!documentDownloadLink( label: document(tointeger(fv!item),"name"), document: fv!item ) ) }, showWhen: or(or(or(not(isnull(ri!NSARequest.Forms.PartABForm.DocumentId)), not(isnull(ri!NSARequest.Forms.PartCForm.DocumentId))), not(isnull(ri!NSARequest.Forms.PartDForm.DocumentId))), not(isnull(ri!NSARequest.Forms.AdditionalDocuments))) )
Discussion posts and replies are publicly visible
Hi anushas0002 ,
As you are trying to display links for the documents that user uploads in the same form, this is not going to work. The way appian deals with document uploads is
When a file is uploaded, the component updates with a temporary Document representing the uploaded file. Between the upload and the form submission, the file on the server is an inactive temporary file and not accessible except through fv! variables described in the File Name, File Description, and Validations parameters. This is the only way to access file metadata before the form is submitted.
In the saveInto for your a!fileUploadField(), you are using the append() function. If you try to append a document to a null value, you will get an array of { null, [document] }. Then when you call the document(tointeger(fv!item), "name") function in the a!forEach(), it will try to retrieve document properties from an array of integers, one of which is a null (the first item in the array), and it will throw an error.
Hi anushas0002,
You can use below code to remove the null values.
reject( isnull(_) , {"",89,null} /* here pass the document list */ )
Thanks
Aditya