In my interface, I user function document.
if( document(tofolder(local!documentId), "size") > 0, true, false )
Discussion posts and replies are publicly visible
You can use the below expression to check first.
isobjectexists("Document", local!documentId)
Create a rule with the below to check whether the document is valid or not.
a!localVariables( local!document: 46,/*ID for any document */ local!contentData: if( isnull(local!document), null, getcontentobjectdetailsbyid(local!document) ), if( isnull(local!document), false(), and( not( exact( local!contentData, "No object with this ID has been found" ) ), find("Type: Document", local!contentData) ) ) )
It must definitely have a value but that is an invalid value. Try to check the variable's value to ensure that it is a single integer value that is a valid document ID.
Where / how is the value of "local!documentId" being set?
FYI, this rule won't work for just-uploaded documents, because it'll indicate that the document is "valid" even when newly uploaded on an unsubmitted form, but the document will still fail when using the "document()" function because the document isn't in an Active/Published status.
Yes I agree.
I do love the "getcontentobjectdetailsbyid()" rule for this though, because it can help us *specifically* distinguish between an already-uploaded file versus a newly-uploaded file. Here's the expression rule I have set up for such a purpose (the "docExists" rule that gets called first just makes sure the doc ID is non null, non zero, and runs the "objectExists()" rule on it first)...
and( rule!ENV_UTIL_docExists(ri!doc), find( "State: Active Published", getcontentobjectdetailsbyid(ri!doc) ) > 0 )
Thanks Mike...
I thought the document ID passed is not valid.
Newly-uploaded documents exist in a "special" system directory in Appian, and are moved to their eventual "target" destination upon Form Submission. While still in that "special" directory, the document() function does not work on them, but they *do* have a valid Doc ID and certain (limited) functions still work on them - such as the "content object details by id" rule.
this is a useful capability to know, because it can be used on-form to judge whether a particular document is previously uploaded or brand new, and control other functionality that depends on this.
Keep in mind that some of these strings like in line 4 are multi-lingual. This might break for other languages.