Expression error in a!foreach()

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

Parents
  • 0
    Certified Lead Developer

    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.

  • Thank you so much for finding it out. It resolved my error. Appreciate your help.

Reply Children
No Data