Unable to detach file from a!fileUploadField

Hello,

I have a problem with a form interface where users are supposed to be able to drop a file with a a!fileUploadField, but if the user tries to detach the file before submitting form or to detach it by updating the record, I have this error :

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error [evaluation ID = U7CHV] : An error occurred while executing a save: Expression evaluation error: Cannot update List of LIH Attach; length of assign value list (0) does not match length of the list to update (1)

I have already used this in another interface and it worked, the only difference is that the value and saveInto are using a relationship this time.

Here is the code :

a!fileUploadField(
                  label: "Pièce jointe",
                  labelPosition: "ABOVE",
                  placeholder: "Placez la pièce jointe ici",
                  target: cons!LIH_GET_ATTACH_CONTRIBUTION,
                  maxSelections: 1,
                  value: ri!recordContribution['recordType!{58f0a27e-e82a-45c8-a2ba-447508f8a5c2}LIH Contribution.relationships.{8b2cb979-71b4-4926-819d-b9cdd9b68eda}lihAttach.fields.{e8f68519-d34f-4654-b900-151916fafe5a}docId'],
                  saveInto: ri!recordContribution['recordType!{58f0a27e-e82a-45c8-a2ba-447508f8a5c2}LIH Contribution.relationships.{8b2cb979-71b4-4926-819d-b9cdd9b68eda}lihAttach.fields.{e8f68519-d34f-4654-b900-151916fafe5a}docId'],
                  validations: {if(
                    or(fv!files.size > 2000000), 
                    "Le fichier ne peut pas faire plus de 2MB. Merci de retirer : " & 
                    index(fv!files, "name", where(fv!files.size > 2000000), {}), 
                    ""
                  )}
                )

Someone already created a topic about this but there was no response in months so I'm asking it again.

Thanks for any help you could provide

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    That's no surprise. You try to write a list with zero items into a single field in a related record.

    I did never try this specific situation myself, but when I try to store document data to a list of records, I do that directly in the saveInto. What I mean is, to run a foreach on save!value creating a record structure for each file, and then store that to the rule input.

  • Thanks for the answer,

    Why is it defined as a list of record ? I'm just targeting a normal field of a normal record but through a relationship, I didn't define it as a list or an array at any moment, why is the rule input considered as a list ? Is it because the relationship is one-to-many ?

  • 0
    Certified Lead Developer
    in reply to SGT FLANAGAN Michael

    Are you new to Appian? The way how Appian data structures work, will take a while to get used to. Yes, this is considered a one-to-many which makes it a list.

    I turned your code into a working example.

    a!localVariables(
      local!case: a!map(
        id: 42,
        documents: null
      ),
      a!fileUploadField(
        label: "Pièce jointe",
        labelPosition: "ABOVE",
        placeholder: "Placez la pièce jointe ici",
        target: tofolder(123),
        maxSelections: 3,
        value: index(local!case.documents, "documentId", null),
        saveInto: a!save(
          target: local!case.documents,
          value: a!forEach(
            items: save!value,
            expression: a!map(
              id: null,
              documentId: fv!item
            )
          )
        ),
        validations: {if(
          or(fv!files.size > 2000000), 
          "Le fichier ne peut pas faire plus de 2MB. Merci de retirer : " & 
          index(fv!files, "name", where(fv!files.size > 2000000), {}), 
          ""
        )}
      )
    )

Reply
  • 0
    Certified Lead Developer
    in reply to SGT FLANAGAN Michael

    Are you new to Appian? The way how Appian data structures work, will take a while to get used to. Yes, this is considered a one-to-many which makes it a list.

    I turned your code into a working example.

    a!localVariables(
      local!case: a!map(
        id: 42,
        documents: null
      ),
      a!fileUploadField(
        label: "Pièce jointe",
        labelPosition: "ABOVE",
        placeholder: "Placez la pièce jointe ici",
        target: tofolder(123),
        maxSelections: 3,
        value: index(local!case.documents, "documentId", null),
        saveInto: a!save(
          target: local!case.documents,
          value: a!forEach(
            items: save!value,
            expression: a!map(
              id: null,
              documentId: fv!item
            )
          )
        ),
        validations: {if(
          or(fv!files.size > 2000000), 
          "Le fichier ne peut pas faire plus de 2MB. Merci de retirer : " & 
          index(fv!files, "name", where(fv!files.size > 2000000), {}), 
          ""
        )}
      )
    )

Children