I am trying to delete a row in a editable grid by "times icon.
a!localVariables( local!deleteDocument: tostring(loggedInUser()), local!a: document(34081, "folderName"), local!documentChildren: a!refreshVariable(folder(1685, "documentChildren")), local!documentChild, local!newFile, local!newFileInfo, local!documentInfo: 'type!{urn:com:appian:types:KONE}CSE_DOCUMENTS'(), local!fileId, local!deleteIndex:0, local!UserDocuments: a!refreshVariable( if( isnull(ri!tenderId), {}, rule!CSE_USERDOCUMENTMATCH( tostring(loggedInUser()), tointeger(ri!tenderId) ) ) ), local!fileList: a!refreshVariable( a!forEach( items: local!documentChildren, expression: a!localVariables( local!documentChild: fv!item, a!forEach( items: local!UserDocuments, expression: if( document(local!documentChild, "name") = document(fv!item.documentid, "name"), if( document(local!documentChild,"id")=tointeger(fv!item.documentid), fv!item,{} ), {} ) ) ) ) ), local!flattenfilelist: a!flatten(local!fileList), a!sectionLayout( contents: { a!richTextDisplayField( labelPosition: "COLLAPSED", value: { a!richTextItem( text: { a!richTextIcon(icon: "FILE", caption: "Name"), " Edit Documents" }, color: "ACCENT", size: "LARGE", style: { "PLAIN" }, showWhen:false(), ) } ), a!fileUploadField( label: "New File Upload", labelPosition: "COLLAPSED", target: cons!CSE_TENDER_COMMENTS_FOLDER, maxSelections: 25, value: local!newFile, showWhen: if( isnull(ri!tenderId), false(), { if( contains( a!forEach( items: rule!CSE_CSETENDER_IDOWNER(ri!tenderId), expression: fv!item ), tostring(loggedInUser()) ), true, false, ) } ), saveInto: { a!save(target: local!newFile, value: save!value), a!save( target: local!fileId, value: tointeger(local!newFile), ), a!save( target: local!documentInfo.DOCUMENT_TYPE_ID, value: a!forEach(items: local!fileId, expression: fv!item) ), a!save( target: local!documentInfo.TITLE, value: a!forEach(items: local!fileId, expression: " ", ) ), a!save( target: local!documentInfo.ENTITY_ID, value: a!forEach( items: local!fileId, expression: ri!tenderId, ) ), a!save( target: local!documentInfo.ACTIVE, value: a!forEach(items: local!fileId, expression: 1) ), a!save( target: local!documentInfo.CREATED_BY, value: a!forEach( items: local!fileId, expression: loggedInUser(), ) ), }, validations: {} ), a!buttonArrayLayout( buttons: { a!buttonWidget( label: "save into Folder", showWhen: if( isnull(ri!tenderId), false(), { if( contains( a!forEach( items: rule!CSE_CSETENDER_IDOWNER(ri!tenderId), expression: fv!item ), tostring(loggedInUser()) ), true, false, ) } ), saveInto: { a!startProcess( processModel: cons!CSE_ADD_CSE_DOCUMENTS, processParameters: { documentId: local!fileId, tenderId: ri!tenderId, user: tostring(loggedInUser()) } ), }, confirmMessage: "You sure you want to upload these files?", style: "PRIMARY", loadingIndicator:true(), submit:true() ) }, align: "START" ), a!columnsLayout( columns: { a!columnLayout( contents: { a!gridLayout( label: "Document list", labelPosition: "COLLAPSED", headerCells: { a!gridLayoutHeaderCell(label: "Document"), a!gridLayoutHeaderCell(label: "Delete") }, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2), a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 1) }, rows: { a!forEach( items: local!flattenfilelist, expression: a!gridRowLayout( contents: { a!linkField( labelPosition: "ABOVE", links: { a!documentDownloadLink( label: document((fv!item.documentid), "name"), document: todocument(fv!item.documentid) ) } ), a!richTextDisplayField( value: { a!richTextIcon( icon: "times", link: { a!submitLink( saveInto: { a!startProcess( processModel: cons!CSE_DOCUMENT_DELELTEBYDOCUMENT, processParameters: { deleteDocument: fv!item.documentid, deleteid: fv!item.id, } ), a!save( target: local!documentChildren, value: folder(1685, "documentChildren") ), a!save( target: local!UserDocuments, value: if( isnull(ri!tenderId), {}, rule!CSE_USERDOCUMENTMATCH(tostring(loggedInUser()), ri!tenderId), ) ), a!save( target:local!flattenfilelist, value:remove(local!flattenfilelist, fv!index) ), /*a!save(target:local!deleteIndex,value:local!deleteIndex+1),*/ }, confirmMessage: "Are you sure you want to delete this file?" ) }, linkStyle: "STANDALONE", showWhen: if( isnull(ri!tenderId), false(), { if( contains( a!forEach( items: rule!CSE_CSETENDER_IDOWNER(ri!tenderId), expression: fv!item ), tostring(loggedInUser()) ), true, false, ) } ), color: "NEGATIVE", ) }, align: "CENTER", ) } ) ) }, selectionSaveInto: {}, validations: {}, shadeAlternateRows: true, ) } ) } ) } ) )
If i click the first time of the times icon it is good, it delete the file and delete the row as i expected, but if i click twice it disappear, but the files is definitely exists in the folder why it report
"Interface Definition: Expression evaluation error at function a!forEach [line 176]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function 'document' [line 184]: Document Does Not Exist or has been Deleted"?
Discussion posts and replies are publicly visible
You have used the document() function that returns the name of the document. Now as you have removed the document by the delete action so the function returns error as it still referencing the document to return its name.
Adding an condition like below against the label attribute of documentdownloadlink can help with the error.
if(rule!APN_isBlank(fv!item.documentid), "", document((fv!item.documentid), "name") )
I just suppose thought the row of the grid has been deleted, but it is actually still exist there and name change to be blank, is this correct? By the way how did you find APN_isBlank rule? You did this project before?
I agree the row is being removed but with the startprocess and multiple saveIntos there seems to be a processing lag within which the document() function is executed. So, the null check can help with the processing delay and thus the expression evaluation error.
As for APN_isBlank(), its a generic rule I assume every developer works with in any environment. So I have not done this project but have seen this rule being used by all the developers.
It still report same error
Any one has any idea? i have put on production by tuesday?
It just remove of the first row i pinpointed, the second one doesn't work, the third one report error