Grid help: editable grid and read only grid

Certified Associate Developer

Hi Appian community I am trying to add a value on to an editable grid 

like this:

 

however my problem is when I try and access the 0's I get this error

I have tried to instantiate all the values as 0 but the array does not seem to register

here is my code thus far for my integer field

a!integerField(
value: and(if(isnull(ri!rank),0,ri!rank[fv!index]),
if(length((ri!rank)>fv!index),0,ri!rank[fv!index])
),
saveInto: ri!rank[fv!index],
required: true
)

any assistance would be greatly appreciated,

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Hi Kevin,

    Could you please provide the code to help further?

    Are you getting an error while adding a new row or enter the value in any column in the grid?

  • 0
    Certified Lead Developer

    What is the intended purpose of the and() statement within the value parameter of this integer field?  It seems like you might be using it wrong.

  • 0
    Certified Associate Developer
    in reply to hemalathak803

      a!localVariables(
        local!readOnly: true,
        local!gridPagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: -1
        ),
        local!rank:ri!rank,
        local!orgFilter,
        local!request: a!queryEntity(
          entity: cons!GFIM_POINTS_TO_DSE_CNA_Request,
          query: a!query(
            logicalexpression: a!queryLogicalExpression(
              operator: "AND",
              filters: {
                if(rule!APN_isEmpty(local!orgFilter),null,
                  a!queryFilter(
                    field: "proponentneedshort",
                    operator: "=",
                    value: group(local!orgFilter[1],"id")
                  )
                )
              },
              ignoreFiltersWithEmptyValues: true
            ),
            pagingInfo: local!gridPagingInfo
          )
        ),
        a!formLayout(
          label: "Rank the CNA gaps",
          contents: {
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!gaugeField(
                      label: "Percent Ranked",
                      percentage: 60.1,
                      primaryText: a!gaugePercentage(),
                      size: "SMALL"
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!buttonArrayLayout(
                      buttons: {
                        a!buttonWidget(
                          label: "Blank rankings ",
                          icon: "filter",
                          style: "NORMAL"
                        )
                      },
                      align: "START"
                    )
                  }
                ),
                a!columnLayout(
                  contents: {
                    a!buttonArrayLayout(
                      buttons: {
                        a!buttonWidget(
                          label: "Export to excel",
                          icon: "download",
                          style: "NORMAL"
                        )
                      },
                      align: "START"
                    )
                  }
                )
              }
            ),
            a!sideBySideLayout(
              items: {
                a!sideBySideItem(
                  item: a!pickerFieldGroups(
                    label: "Organization Search",
                    labelPosition: "ABOVE",
                    maxSelections: 1,
                    value: local!orgFilter,
                    saveInto: local!orgFilter,
                    validations: {}
                  )
                ),
                a!sideBySideItem(
                  item: a!textField(
                    label: "search box",
                    labelPosition: "ABOVE",
                    saveInto: {},
                    refreshAfter: "UNFOCUS",
                    validations: {}
                  )
                ),
                a!sideBySideItem(
                  item: a!buttonArrayLayout(
                    buttons: {
                      a!buttonWidget(
                        label: if(local!readOnly,"Edit Information","Save Information"),
                        saveInto: a!save(local!readOnly, not(local!readOnly)),
                        style: if(local!readOnly,"SECONDARY","PRIMARY")
                      )
                    },
                    align: "END",
                    marginBelow: "NONE"
                  )
                )
              },
              alignVertical: "BOTTOM"
            ),
            a!gridLayout(
              label: "",
              totalCount: count(local!request),
              headerCells: {
                a!gridLayoutHeaderCell(label: "Organization" ),
                a!gridLayoutHeaderCell(label: "Short Title" ),
                a!gridLayoutHeaderCell(label: "Capability Need / Shortfalls" ),
                a!gridLayoutHeaderCell(label: "Recommended Solution" ),
                a!gridLayoutHeaderCell(label: "Justification for FDU" ),
                a!gridLayoutHeaderCell(label: "Authority" ),
                a!gridLayoutHeaderCell(label: "Risk" ),
                a!gridLayoutHeaderCell(label: "Documents" ),
                a!gridLayoutHeaderCell(label: "Ranking" )
                
              },
              /* Only needed when some columns need to be narrow */
              columnConfigs: {
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:1 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:2 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:2 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:1 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:1 ),
                a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:2 )
               
              },
              /*
              * a!forEach() will take local!employee data and used that data to loop through an
              * expression that creates each row.
              *
              * When modifying the recipe to work with your data, you only need to change:
              * 1.) the number of fields in each row
              * 2.) the types of fields for each column (i.e. a!textField() for text data elements)
              * 3.) the fv!row elements. For example fv!item.firstName would change to fv!item.yourdata
              */
              rows: a!forEach(
                items: local!request,
                expression: a!gridRowLayout(
                  id: fv!index,
                  contents: {
                    /* Proponent for the Need / Shortfall*/
                    a!textField(
                      value:{ if(rule!APN_isEmpty(fv!item.proponentneedshort),
                      "",group(tointeger(fv!item.proponentneedshort),"groupName"))},
                      saveInto: fv!item.proponentneedshort,
                      readOnly: true
                    ),
                    /* For the Short Title Column*/
                    a!textField(
                      value: fv!item.shorttitle,
                      saveInto: fv!item.shortTitle,
                      link:a!startProcessLink(
                        processModel: cons!GFIM_POINTS_TO_PM_CNA_REQUEST,
                        processParameters: local!request.data
                      ),
                      readOnly: true
                    ),
                    /* For the Capability Need / Shortfalls*/
                    a!textField(
                      value: fv!item.capabilityneedshort,
                      saveInto: fv!item.CapabilityNeedShort,
                      readOnly: true
                    ),
                    /*Recommended Solution*/
                    a!textField(
                      value: fv!item.recommentedsolution,
                      readOnly: true
                    ),
                    /* For the Justification for FDU Column*/
                    a!textField(
                      value: fv!item.justificationfdu,
                      readOnly: true
                    ),
                    /*Authority*/
                    a!textField(
                      value: fv!item.authority,
                      readOnly: true
                    ),
                    /* For the risk Column*/
                    a!textField(
                      value: fv!item.risk,
                      readOnly: true
                    ),
                   /*documents*/
                    a!richTextDisplayField(
                      value: {
                        a!forEach(
                          items: fv!item.documentsWorkSpace,
                          expression:
                          a!richTextItem(
                            text: {
                              a!richTextIcon(icon: rule!GFIM_getDocumentIcon(extensionType: document(fv!item,"extension")))," ",
                              document(fv!item,"name"),
                              if(fv!isLast,null,char(10))
                            },
                            link: a!documentDownloadLink(document: fv!item)
                          )
                        )
                      }
                    ),
                    a!integerField(
                      value: or(if(isnull(ri!rank),0,ri!rank[fv!index]),
                      if(length((ri!rank)>fv!index),0,ri!rank[fv!index])
                        ),
                      saveInto:   ri!rank[fv!index],
                      required:  true
                    )
                    
                   
                  }
                )
              ),
              showWhen: not(local!readOnly),
              rowHeader: 1
            ),
            a!gridField(
              label: "Read-only Grid",
              labelPosition: "COLLAPSED",
              data: local!request.data,
              columns: {
                a!gridColumn(
                  label: "Organization",
                  sortField: "proponentneedshort",
                  value: group(tointeger(fv!row.proponentneedshort),"groupName")
                ),
                a!gridColumn(
                  label: "Short Title",
                  sortField: "shorttitle",
                  value: fv!row.shorttitle
                  /*link:a!recordLink(*/
                    /*label:fv!row.shorttitle,*/
                  /*)*/
                /*  */
                ),
                a!gridColumn(
                  label: "Capability Need / Shortfalls",
                  sortField: "capabilityneedshort",
                  value: fv!row.capabilityneedshort
                ),
                a!gridColumn(
                  label: "Recommended Solution",
                  sortField: "recommentedsolution",
                  value: fv!row.recommentedsolution
                ),
                a!gridColumn(
                  label: "Justification for FDU",
                  sortField:"justificationfdu",
                  value:  fv!row.justificationfdu
                ),
                a!gridColumn(
                  label: "Authority",
                  sortField: "authority",
                  value: fv!row.authority
                ),
                a!gridColumn(
                  label: "Risk",
                  sortField: "risk",
                  value: fv!row.risk
                ),
                a!gridColumn(
                  label: "Documentation",
                  value:  a!richTextDisplayField(
                    value: {
                      a!forEach(
                        items: fv!row.documentsWorkSpace,
                        expression:
                        a!richTextItem(
                          text: {
                          
                            document(fv!item,"name")
                        
                          },
                          link: a!documentDownloadLink(document: fv!item)
                        )
                      )
                    }
                  )
                ),
                a!gridColumn(
                  label: "Ranking",
                  sortField: "ranking",
                  value: fv!row.ranking
                )
              },
              pageSize: 5,
              initialSorts: {
                a!sortInfo(
                  field: "proponentneedshort"
                )
              },
              showWhen: local!readOnly,
              validations: {}
            )
            
          },
          buttons: a!buttonLayout(
            primaryButtons: a!buttonWidget(
              label: "Submit",
              submit: true
            )
          )
        )
      )

  • 0
    Certified Associate Developer
    in reply to hemalathak803

    its giving me when it attempts to load

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    I am attempting to do a null check and an "out of bounds" check where the index goes out of bounds which is what I got out of the error message

  • +1
    Certified Lead Developer
    in reply to kevinr0001

    The problem is, you're setting the value directly to the result of the evaluation of the and() expression, which is a boolean (true/false) value only, and I expect that's not what you actually want.  You probably just want to make use of the index() function (no relation to fv!index which you're already using), which inherently ensures the position you're accessing actually exists within the array.

    value: index(ri!rank, fv!index, 0),

  • 0
    Certified Lead Developer
    in reply to kevinr0001

    As a general tip, when posting long code like this, please use the Insert --> Insert Code functionality and paste your code into the provided text box - this helps with keeping formatting/indentation straight, as well as preventing the post from being overwhelmed by pages and pages of code unnecessarily.

    Also: the reasoning behind the more recent error message you screenshotted, seems to be an extra "(" in your length() function call:  length((ri!rank)>fv!index) -- here, instead of getting the length of ri!rank and comparing it to fv!index like you intended, you're actually attempting to get the length of ( ri!rank > fv!index ), which is invalid since ri!rank is an array and therefore the ">" comparison is invalid.

    This would be easier to troubleshoot if you use more standard linebreaks and indentation in your logic, i.e. more like this:

    /* this contains no changes other than adjusted linebreaks and indentation, for clarity and readability */
    a!integerField(
      value: or(
        if(
          isnull(ri!rank),
          0,
          ri!rank[fv!index]
        ),
        if(
          length((ri!rank) > fv!index),
          0,
          ri!rank[fv!index]
        )
      ),
      saveInto: ri!rank[fv!index],
      required: true
    )

    In the above we can see that this code is still fundamentally problematic (as i noted in my reply further down-thread); you're setting the value of the integer field to the result of the or() expression (i guess you changed this from your earlier and() call), but here the result will still be a boolean value, which I'm not sure is your intention (unless ri!rank itself is a boolean value which is unclear).  The length() expression call can be fixed by removing the unnecessary set of parenthesis, like this: length(ri!rank) > fv!index.  However I think you might actually just want to replace this whole expression with a single instance of the index() function like I described in my earlier reply below.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thanks Mike that is exactly what I needed , and I will try to work on my code format