Hi All,
I am working on a use case, where I have configured "Remove Document" using a dynamic link in a grid row layout per below code, to remove the uploaded document from the interface. But as soon I click on this Remove link, rule or perhaps grid is throwing this error. Please suggest how can I fix this issue. Thanks a lot in advance
Error:
Interface Definition: Expression evaluation error at function a!forEach [line 115]: Error in a!forEach() expression during iteration 1: Expression evaluation error in rule 'FICO_rule_getimagefordocumenttype' at function 'document' [line 3]: Document Does Not Exist or has been Deleted
Code:
if( rule!APN_isEmpty( ri!FICO_documents ), a!richTextDisplayField( value: { a!richTextItem( text: "No Documents found for this Case", style: { "EMPHASIS", "STRONG" }, size: "MEDIUM", color: "NEGATIVE" ) } ), load( local!pagingInfo: a!pagingInfo( 1, 5, a!sortInfo( field: "createdDateTime", ascending: false ) ), local!switch: true, local!dataSubset: a!forEach( items: ri!FICO_documents, expression: 'type!{urn:com:SVB:types:FICO}FICO_documents'( documentName: fv!item.documentName, createdBy: fv!item.createdBy, createDateTime: fv!item.createDateTime ) ), with( { a!sectionLayout( label: upper( "documents history" ), isCollapsible: true, contents: { a!richTextDisplayField( /*label: local!switch,*/ value: a!richTextItem( text: if( local!switch, "Hide Documents", "Show Documents" ), style: { "STRONG" }, link: a!dynamicLink( saveInto: a!save( local!switch, if( local!switch, false, true ) ) ), linkStyle: "STANDALONE", size: "MEDIUM" ), ), /*Extra Space*/ a!richTextDisplayField(), /*Doc Grid*/ a!columnsLayout( columns: { a!columnLayout( contents: { a!gridLayout( headerCells: { a!gridLayoutHeaderCell( label: "Document" ), a!gridLayoutHeaderCell( label: "Uploaded By" ), a!gridLayoutHeaderCell( label: "Uploaded On" ), a!gridLayoutHeaderCell( label: "Remove", /*showWhen: and(*/ /*isusermemberofgroup(*/ /*loggedInUser(),*/ /*cons!FICO_GROUP_CAS_TEAM*/ /*),*/ /*ri!allowDocDeletion = true*/ /*)*/ ) }, columnConfigs: { a!gridLayoutColumnConfig(), a!gridLayoutColumnConfig(), a!gridLayoutColumnConfig(), a!gridLayoutColumnConfig( width: "NARROW", /*showWhen: and(*/ /*isusermemberofgroup(*/ /*loggedInUser(),*/ /*cons!FICO_GROUP_CAS_TEAM*/ /*),*/ /*ri!allowDocDeletion = true*/ /*)*/ ) }, rows: a!forEach( items: ri!FICO_documents, expression: a!gridRowLayout( id: fv!index, contents: { a!richTextDisplayField( value: { a!richTextItem( text: rule!FICO_RULE_getImageForDocumentType( document: ri!FICO_documents.documentId[fv!index] ) ), a!richTextItem( text: " " ), a!richTextItem( text: if( rule!APN_isBlank( ri!FICO_documents.documentId ), {}, if( contains( touniformstring( getcontentobjectdetailsbyid( ri!FICO_documents.documentId[fv!index] ) ), "No object with this ID has been found" ), "", document( ri!FICO_documents.documentId[fv!index], "name" ) & "." & document( ri!FICO_documents.documentId[fv!index], "extension" ), ) ), link: a!documentDownloadLink( document: ri!FICO_documents.documentId[fv!index] ), linkStyle: "STANDALONE", size: "MEDIUM" ) } ), a!textField( value: ri!FICO_documents.createdBy[fv!index], readOnly: true ), a!textField( value: ri!FICO_documents.createDateTime[fv!index], readOnly: true ), a!imageField( images: a!documentImage( document: a!iconIndicator( "REMOVE" ), caption: "Remove Document", link: a!dynamicLink( value: fv!index, saveInto: { a!startProcess( processModel: cons!FICO_PROCESS_DELETE_FILE, processParameters: { document: ri!FICO_documents.documentId[fv!index] }, onSuccess: { a!save( ri!FICO_documents, remove( ri!FICO_documents, fv!index ) ) } ) } ) ), /*showWhen: and(*/ /*isusermemberofgroup(*/ /*loggedInUser(),*/ /*cons!FICO_GROUP_CAS_TEAM*/ /*),*/ /*ri!allowDocDeletion = true*/ /*)*/ ) } ) ), showWhen: local!switch ), } ), a!columnLayout( contents: { a!forEach( items: ri!FICO_documents, expression: { a!columnsLayout( columns: { a!columnLayout( contents: { a!richTextDisplayField(), a!richTextDisplayField(), a!richTextDisplayField( value: a!richTextItem( text: a!richTextIcon( icon: if( rule!APN_isBlank( local!dataSubset[fv!index].documentId ), "eye", "eye-slash" ), caption: if( rule!APN_isBlank( local!dataSubset[fv!index].documentId ), cons!FICO_TEXT_LABEL_OPEN_DOCUMENT_PREVIEW, cons!FICO_TEXT_LABEL_CLOSE_DOCUMENT_PREVIEW ), color: "ACCENT", size: "LARGE", showWhen: if( or( document( ri!FICO_documents.documentId[fv!index], "extension" ) = "docx", document( ri!FICO_documents.documentId[fv!index], "extension" ) = "pptx", document( ri!FICO_documents.documentId[fv!index], "extension" ) = "xlsx" ), false, true ) ), link: if( rule!APN_isBlank( fv!item.documentId ), a!dynamicLink( saveInto: { a!save( local!dataSubset[fv!index].documentId, ri!FICO_documents[fv!index].documentId ) } ), a!dynamicLink( saveInto: { a!save( local!dataSubset[fv!index].documentId, "" ) } ) ), linkStyle: "STANDALONE" ) ) } ) } ), a!documentViewerField( label: "Document Name: " & document( fv!item.documentId, "name" ) & "." & document( fv!item.documentId, "extension" ), document: todocument( fv!item.documentId ), showWhen: and( not( rule!APN_isBlank( fv!item.documentId ) ), if( or( document( ri!FICO_documents.documentId[fv!index], "extension" ) = "docx", document( ri!FICO_documents.documentId[fv!index], "extension" ) = "pptx", document( ri!FICO_documents.documentId[fv!index], "extension" ) = "xlsx" ), false, true ) ) ), } ) } ), } ), } ) } ) ) )
Discussion posts and replies are publicly visible
This speaks to larger issues in your implementation, I think.
The biggest, to me at least: why are you using an interface click, with no (possible) confirmation, to permanently delete a document from the back-end?
In general, I've found that it's almost always the best practice to not hard-delete documents from user-controllable interfaces/processes, no matter what the use case -- instead, you should either deactivate the document (when using a DB-backed system; in other words have a data element in your CDT called "is_deleted" or simlar) or move it to a special "removed" location. In either of these cases, the file will still be "around" and therefore you wouldn't end up with the system-breaking errors you've described. Your grid row would then be able to easily check for "deletion status" on a row-by-row basis and simply not display the row for a deleted document (or, still display the row but alter the display, and allow the user to undo an accidental click).
Also just from a code cleanliness perspective - I see a ton of references to "ri!FICO_documents.documentId[fv!index]", etc, where you should just be actually using the functionality provided in a!forEach() and calling "fv!item.documentId", and similar. I assume this might be a remnant from updates to older code, so take that with a grain of salt.
Mike, I am having issue accessing a document after uploading it. This is the error I am getting -
(Expression evaluation error at function a!forEach: Error in a!forEach() expression during iteration 2: Expression evaluation error at function 'document' [line 7]: Document Does Not Exist or has been Deleted) (Data Outputs).
NOTE 1 - It works sometimes and fails at other times, like say it works for upto 2 files. Once I upload 3 or more (the max is set to 5), the files are getting uploaded FINE but the script task where I capture the document details FAILS.
I am using the below code in the output node of a Script task to append to a CDT which is used to update the data in a "Document" table in the database.
NOTE 2 - The file_documents is set to todocument(uploadedfiles) where uploadedfiles is the variable that holds the uploaded files - like Document: 1110 etc.
a!forEach( items: pv!file_documents, -> passed from ui as integer(uploadedfiles) which I later convert in another script task to todocument. expression: 'type!{urn:com:appian:types}Document'( doc_id: document(fv!item, "id"), type: document(fv!item, "extension"), title: document(fv!item, "name"), ) )
NOTE 3 - I tried executing the above code in a sub process as well both synchronously and asynchronously but the results are very random like it would work sometimes and fail other times.
NOTE 4 - The entire process is NOT activity chained why because I know from prior experience that the file handle won't be available in the process model if activity chaining is enabled, that was in version 18.4. Now I am on 20.4.
Can you throw some light?
PS - I have asked for the contenttools plugin to be installed which I have used in my previous job to get the document id based on filename. I am hoping that will help.