Hi All,
I'm getting below expression error when trying to create a grid to display comments or documents. Please suggest how can I resolve this error? Thanks in advance.
Error: Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!forEach [line 89]: “Invalid index: Cannot index property ’’documentId’’ of type String into type List of Variant
/*Choice variable has two values 1 --> Documents (Comments CDT is empty) 2 --> Comments (Documents CDT is empty) */ load( local!choice: if( rule!APN_isBlank( ri!REGAL_comment ), 1, 2 ), local!pagingInfo: a!pagingInfo( 1, 5, a!sortInfo( field: if( local!choice = 1, "createDateTime", "createdDateTime" ), ascending: false ) ), local!switch: true, with( local!dataSubset: if( local!choice = 1, todatasubset( ri!REGAL_documents, local!pagingInfo ), todatasubset( ri!REGAL_comment, local!pagingInfo ) ), { a!richTextDisplayField( /*label: local!switch,*/ value: a!richTextItem( text: if( local!switch, "Hide ", "Show " ) & if( local!choice = 1, "Documents History", "Comments History" ), style: { "EMPHASIS", "STRONG" }, link: a!dynamicLink( saveInto: a!save( local!switch, if( local!switch, false, true ) ) ), linkStyle: "STANDALONE" ), showWhen: ri!readFromRecord = false ), a!gridField_19r1( columns: if( local!choice = 1, /*Documents Grid*/ { a!gridTextColumn( label: "Document Name", field: "documentName", data: a!forEach( items: index( local!dataSubset.data, "documentId", null ), expression: document( fv!item, "name" ) ), links: a!forEach( items: local!dataSubset.data.documentId, expression: a!documentDownloadLink( document: todocument( fv!item ) ) ) ), a!gridTextColumn( label: "Uploaded By", field: "createdBy", data: a!forEach( items: index( local!dataSubset.data, "createdBy", null ), expression: user( fv!item, "firstName" ) & " " & user( fv!item, "lastName" ) ) ), a!gridTextColumn( label: "Uploaded On", field: "createDateTime", data: index( local!dataSubset.data, "createDateTime", null ) ), a!gridImageColumn( label: "", field: "documentId", data: a!forEach( items: index( local!dataSubset.data, "documentId", null ), expression: a!documentImage( document: a!iconIndicator( "REMOVE" ), caption: "Remove Document", link: a!dynamicLink( value: fv!index, saveInto: { a!startProcess( processModel: cons!DELETE_DOCUMENT, processParameters: { document: ri!REGAL_documents.documentId[fv!index] }, onSuccess: { a!save( ri!REGAL_documents, remove( ri!REGAL_documents, fv!index ) ) } ) } ) ) ), showWhen: false/*ri!isInitiator = true()*/ ) }, /*Comments Grid*/ { a!gridTextColumn( label: "Comment", field: "commentDescription", data: index( local!dataSubset.data, "commentDescription", null ) ), a!gridTextColumn( label: "Commented By", field: "createdBy", data: a!forEach( items: index( local!dataSubset.data, "createdBy", null ), expression: if( rule!APN_isBlank( fv!item ), fv!item, user( fv!item, "firstName" ) & " " & user( fv!item, "lastName" ) ) ) ), a!gridTextColumn( label: "Commented On", field: "createdDateTime", data: index( local!dataSubset.data, "createdDateTime", null ) ) } ), totalCount: local!dataSubset.totalCount, value: local!pagingInfo, saveInto: local!pagingInfo, showWhen: local!switch ) } ) )
Discussion posts and replies are publicly visible
what is the type of ri!REGAL_documents? If it is of type "Any type" cast it to your CDT first then try.
You use the index function to attempt to find the dataSubset.data's documentId just moments before in line 79, but you don't use the index function again to do the exact same thing moments later in line 89. Notice that the same operation using the index() function instead of dot notation worked, at least appears to be working well, because the error message was reported on line 89 and not on line 79.
It's because your datasubset is only conditionally set to a particular local variable, and possibly they have different types. Unless all the types the datasubset.data could possibly be have the same field, you should expect it to break. Even if they both do, I wouldn't be surprised if Appian still responds by setting the type to "Any Type" with no idea how to proceed with the dot notation.
Best to use the index, or better still the property function. Property and index work the same way in this instance, but property is restricted to finding named properties and more explicitly states what you're trying to do.
Unknown said:or better still the property function
I second this. Note, I don't think it's necessarily accurate to say property() is *restricted to* finding named properties (i believe both functions map to each other pretty much 1:1), but it's a very good idea for code readability to use property() for named properties and index() for indexes into an array.
In addition to what already said, I note that you're using `a!gridField_19r1` in your interface, implying that you're on 19.2 or higher - in which case, I strongly suggest you look into using the new style paging grid instead, as it's far easier to configure (for example, for your first column, in the new style grid you wouldn't need to loop over your data set once for the data: parameter and again for the links: parameter...)
This would pay off because it would instantly help your debugging efforts for errors like this due to the far simpler configuration.
Thank you so much for finding it out. It resolved my error. Appreciate your help.
Yes Mike, I now changed it to the newer paging style grid and its more feasible to debug now. Thank you so much for the suggestion.
We would both appreciate it if you could confirm one or maybe both of our answers.