File upload validation

I'm using the following code to validate a user uploaded file : 

 

a!gridRowLayout(
id: ri!index,
contents: {
if(
ri!index > ri!oldAttachments,
a!fileUploadField_17r1(
label: "file upload " & ri!index,
target: ri!target,
value: ri!attachments[ri!index],
saveInto: ri!attachments[ri!index],
validations:{
if(
or(
find("JPG", a!fileUploadField(value: ri!attachments)),
find("JPEG", a!fileUploadField(value: ri!attachments)),
find("PNG", a!fileUploadField(value: ri!attachments)),
find("ICO", a!fileUploadField(value: ri!attachments)),
find("GIF", a!fileUploadField(value: ri!attachments)),
find("BMP", a!fileUploadField(value: ri!attachments))
)>0,"Invalid Format",{}

) } 

 

... 

 

but it gives an error in a!for Each() while uploading another file 

  Discussion posts and replies are publicly visible

Parents Reply Children
  • The piece of code named "AttachmentsGridRow" is called in a!applyComponents within a!gridLayout as follows:

    a!gridLayout(

    instructions: "Accepted Formats: docsx, xlsx, pdf",
    label: "Attachments",
    emptyGridMessage: "No files have been attached to this record",
    headerCells: {
    a!gridLayoutHeaderCell(label: "File"),
    a!gridLayoutHeaderCell(label: "Uploaded On", align: "RIGHT"),
    if(
    ri!readOnly,
    {},
    a!gridLayoutHeaderCell()
    )
    },
    columnConfigs: {
    a!gridLayoutColumnConfig(weight: 7),
    a!gridLayoutColumnConfig(weight: 3),
    if(
    ri!readOnly,
    {},
    a!gridLayoutColumnConfig(width: "ICON")
    )
    },
    rows: a!applyComponents(
    function: rule!AttachmentsGridRow(

    attachments: ri!documents,
    deletedAttachments: ri!deletedDocuments,
    index: _,
    readOnly: ri!readOnly,
    oldAttachments: local!oldAttachments,
    target: ri!target
    ),
    array: if(
    or(isnull(ri!documents), count(ri!documents) < 1),
    {},
    1+enumerate(count(ri!documents))
    )

    ),
    addRowLink: if(
    ri!readOnly,
    null,
    a!dynamicLink(
    label: "Attach New File",
    value: todocument(null),
    saveInto: a!save(ri!documents, append(ri!documents, save!value))
    )
    )

    currently, there is no error message as I have used "a!fileUploadField" instead of "a!fileUploadField_17r1" and the validations are valid , but now each "upload file" segment occupies two rows in the attachments grid on the dashboard and both the occupied rows both contain the "+" sign to add files, but when I try to add files in the 2nd row after adding in the 1st row, they are not uploaded in the 2nd row. Apologies, Its a little difficult to explain