Skip to main content
chrisg0006
April 5, 2024
Question

Expression Error when removing a document from the file upload component.

  • April 5, 2024
  • 4 replies
  • 1 view

I have a form that is used to upload documents.  The form works as intended except when removing a document the user just uploads.  Typically, a user can hover over the document icon and it will turn into a "X".  The user can click on that and remove the document so that another document can be uploaded in its place.  When the user does this, the following error is thrown.

Expression evaluation error at function a!fileUploadField: An error occurred while executing a save: java.lang.ArrayIndexOutOfBoundsException: Invalid index (1) for list: valid range is empty.

The code for the fileuploadfield is:

a!fileUploadField(
              label: "File Upload",
              labelPosition: "ABOVE",
              instructions: "Use this to upload speaker documents.",
              target: tofolder(ri!speakerRecord['recordType!PMSO Speaker.fields.speakerFolderId']),
              maxSelections: 1,
              value: local!file,
              saveInto: {
                a!save(local!file,save!value),
                a!save(local!spkrDocRecord['recordType!PMSO Speaker Document.fields.speakerDocumentNo'], local!file[1])
              },
              showWhen: a!isNotNullOrEmpty(local!spkrDocRecord['recordType!PMSO Speaker Document.fields.speakerDocumentTypeId']),
              validations: {}
            ),

4 replies

chrisg0006
April 5, 2024

I solved my own problem. I modified the code to check to see if the local!file is null or empty.  The code now looks like this.

a!fileUploadField(
              label: "File Upload",
              labelPosition: "ABOVE",
              instructions: "Use this to upload speaker documents.",
              target: tofolder(ri!speakerRecord['recordType!PMSO Speaker.fields.speakerFolderId']),
              maxSelections: 1,
              value: local!file,
              saveInto: {a!save(local!file,save!value),
                if(a!isNotNullOrEmpty(local!file),
                a!save(local!spkrDocRecord['recordType!PMSO Speaker Document.fields.speakerDocumentNo'], local!file[1]),
                ""
                )
                },
              showWhen: a!isNotNullOrEmpty(local!spkrDocRecord['recordType!PMSO Speaker Document.fields.speakerDocumentTypeId']),
              validations: {}

Does anyone else have a better solution?  This seems to work.

stefanhelzle0001
Brainy
April 5, 2024

Nothing wrong with it, just a bit clumsy. I did not test the below code, but give it a try.

{
  a!save(
    target: local!spkrDocRecord['recordType!PMSO Speaker Document.fields.speakerDocumentNo'],
    value: index(save!value, 1, null)
  )
}

shubhama926776
Brainy
April 5, 2024

Why are you using local!file instead you can directly use local!spkrDocRecord.

शुभम्