Invalid Function 'document'

Hi all, our team want to create a validation on the fly to verify the size of a document that is uploaded. However, it's giving this error:

Error evaluating function 'document' : Expression evaluation error : Invalid function document.

Is there any way i can solve this?

Our idea is to create some validations (about the document) before the form is submitted. But, since the document ID doesn't exists before the form is submitted, we cant apply the document fucntion to retrieve some document properties.

Here is the sample code:

=a!formLayout(
label: "Lorem Ipsum",
instructions: "Lorem Ipsum",
firstColumnContents: {
a!fileUploadField(
label: "Upload resume",
instructions: "Any format is acceptable.",
target: ri!targetFolder,
value: ri!file,
saveInto:ri!file,
required: true,
validations:
if(isnull(ri!file), null, if(document(todocument(ri!file), "size") > 1000, "BIG", "SMALL"))


)
},
secondColumnContents: {},
buttons: a...

OriginalPostID-264348

  Discussion posts and replies are publicly visible

  • ...!buttonLayout(
    primaryButtons: {
    a!buttonWidgetSubmit(
    label: "Submeter",
    style: "PRIMARY",
    saveInto: {}
    )
    }

    ),
    validations: {

    }
    )
  • Idk how practical this will sound to you, but you could psuedo submit the form after an upload and re-loop back into the form (in a way that is not noticeable to the user) so the document IDs are updated & become valid if it is imperative the validation is done right after upload.

    Maybe another practitioner has a better solution.
  • Hi fredericom, This may help you!!!

    a!fileUploadField(
    value: ri!doc,
    saveInto: ri!doc,
    validations:{
    if(
    a!fileUploadField(value:ri!doc).uploadedDocumentSize > 100 /*in KB's*/,
    "Exceed maximum size",
    ""
    )
    }
    )
  • 0
    Certified Lead Developer
    @fredericom, backing up a little bit, you should be aware that you can't use document() to access properties for a just-uploaded file on a SAIL form because the uploaded document lives in a special temporary system folder which is not user-accessible except through a!fileUploadField. The "standard recommendation" from Appian is to verify file properties after submitting a form and seamlessly looping back onto the form again, as Reggie says above, because after form submit you have access to the actual document ID / properties.

    Users have discovered a workaround similar to what Venkatesh suggests above - i.e. you pass the local variable containing the newly uploaded file back through a!fileUploadField to get certain Dot Properties that can tell you some information about it, namely filename and size.
    However it is important to note that the uploaded document size readout this gives is *rendered as plaintext and abbreviated* - i.e. "5 kb", "2.3 mb", so a simple numeric operator will not work by itself. If one has critical need of doing size comparison on-form, you'd need to write a custom expression rule that takes different size text values and parses them to a standardized value (i.e. multiply out to get bytes for the various different suffixes), and live with dealing in approximate values at the end of the day.
  • 0
    Certified Lead Developer
    Just as a heads up, I've heard that the workaround suggested by venkatesh above no longer works on 17.1 - maybe worth testing though.
  • 0
    Certified Lead Developer
    @Philb: I've had a chance to test in 17.1 after seeing someone claim it stopped working in another thread - it still seems to work the exact same way for me and the user who made that claim never followed up with any further detail when I asked. So for now it's probably not a concern.