How to save data identifier into a local variable in a readonly grid?

Certified Associate Developer

Hi everyone, I'm facing issue while saving unique identifier value into a local variable. By default indexes are getting saved but I want to save the identifier value so that even if custom filters are applied only the actual selected value is checked/selected in the grid.

The working approach I came up till now is to convert my data into a datasubset using a!dataSubset and then use todatasubset with fv!pagingInfo from the grid. The issue which I found with this is todatasubset function is not able to over ride the paging configured by a!dataSubset, it could very well be an Appian issue not sure but due to this I'm getting full grid data in the screen. (Screenshot attached for this below)




If you know any workaround for this or any approach you implemented for this use case please share!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Hey  ,  

    a!localVariables(
      local!selection,
      local!selectedEmployees,
      local!employeeDS: {
        {
          id: 11,
          name: "Sophia Turner",
          dept: "Marketing"
        },
        {
          id: 22,
          name: "Liam Brown",
          dept: "Operations"
        },
        {
          id: 33,
          name: "Emma Davis",
          dept: "Product Management"
        },
        {
          id: 44,
          name: "Oliver Martinez",
          dept: "Engineering"
        },
        {
          id: 55,
          name: "Ava Wilson",
          dept: "Customer Support"
        },
        { id: 66, name: "Noah Garcia", dept: "Sales" },
        {
          id: 77,
          name: "Isabella Lee",
          dept: "Human Resources"
        },
        { id: 88, name: "James Smith", dept: "IT" },
        {
          id: 99,
          name: "Mia Johnson",
          dept: "Finance"
        },
        { id: 111, name: "Ethan Brown", dept: "Legal" }
      },
      local!ds: a!dataSubset(
        data: local!employeeDS,
        startIndex: 1,
        batchSize: - 1,
        totalCount: length(local!employeeDS),
        identifiers: index(local!employeeDS, "id", {})
      ),
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!gridField(
                  label: "Employee Directory",
                  data: todatasubset(
                    arrayToPage: local!ds,
                    pagingConfiguration: fv!pagingInfo
                  ),
                  columns: {
                    a!gridColumn(
                      label: "Name",
                      sortField: "name",
                      value: fv!row.name
                    ),
                    a!gridColumn(
                      label: "Department",
                      sortField: "dept",
                      value: fv!row.dept
                    )
                  },
                  pageSize: 5,
                  selectable: true,
                  selectionValue: local!selection,
                  selectionSaveInto: {
                    local!selection,
                    a!save(
                      local!selectedEmployees,
                      index(
                        fv!selectedRows,
                        length(fv!selectedRows),
                        null
                      )
                    )
                  }
                )
              }
            )
          }
        )
      }
    )


    To simplify my question, I need to add pagination to the code above. How can I achieve this given I need the id to be stored in local!selection.

  • +1
    Certified Lead Developer
    in reply to deepakrana77

    try this variation:

    a!localVariables(
      local!selection: {},
      local!selectedEmployees,
      local!employeeList: {
        {
          id: 11,
          name: "Sophia Turner",
          dept: "Marketing"
        },
        {
          id: 22,
          name: "Liam Brown",
          dept: "Operations"
        },
        {
          id: 33,
          name: "Emma Davis",
          dept: "Product Management"
        },
        {
          id: 44,
          name: "Oliver Martinez",
          dept: "Engineering"
        },
        {
          id: 55,
          name: "Ava Wilson",
          dept: "Customer Support"
        },
        { id: 66, name: "Noah Garcia", dept: "Sales" },
        {
          id: 77,
          name: "Isabella Lee",
          dept: "Human Resources"
        },
        { id: 88, name: "James Smith", dept: "IT" },
        {
          id: 99,
          name: "Mia Johnson",
          dept: "Finance"
        },
        { id: 111, name: "Ethan Brown", dept: "Legal" }
      },
      
      local!ds: a!dataSubset(
        data: local!employeeList,
        startIndex: 1,
        batchSize: -1,
        totalCount: length(local!employeeList),
        identifiers: index(local!employeeList, "id", {})
      ),
      
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!gridField(
                  label: "Employee Directory",
                  data: todatasubset(
                    arrayToPage: local!employeeList,
                    pagingConfiguration: fv!pagingInfo
                  ),
                  columns: {
                    a!gridColumn(
                      label: "Name",
                      sortField: "name",
                      value: fv!row.name
                    ),
                    a!gridColumn(
                      label: "Department",
                      sortField: "dept",
                      value: fv!row.dept
                    )
                  },
                  pageSize: 5,
                  selectable: true(),
                  selectionValue: wherecontains(local!selection, local!employeeList.id),
                  selectionSaveInto: {
                    a!save(
                      local!selection,
                      if(
                        a!isNullOrEmpty(save!value),
                        {},
                        property(
                          index(local!employeeList, save!value, {}),
                          "id",
                          {}
                        )
                      )
                    ),
                    
                    /*a!save(
                      local!selectedEmployees,
                      index(
                        fv!selectedRows,
                        length(fv!selectedRows),
                        null
                      )
                    )*/
                  }
                )
              }
            )
          }
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Ah in the chaotic identifier search I didn't thought the other way around. The OG wherecontains did the trick, thanks for your help!

  • +1
    Certified Lead Developer
    in reply to deepakrana77

    Directly storing the identifiers works like a charm!

    a!localVariables(
      local!selection: {},
      local!pInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 5,
        sort: a!sortInfo("name", true)
      ),
      local!employeeList: {
        {
          id: 11,
          name: "Sophia Turner",
          dept: "Marketing"
        },
        {
          id: 22,
          name: "Liam Brown",
          dept: "Operations"
        },
        {
          id: 33,
          name: "Emma Davis",
          dept: "Product Management"
        },
        {
          id: 44,
          name: "Oliver Martinez",
          dept: "Engineering"
        },
        {
          id: 55,
          name: "Ava Wilson",
          dept: "Customer Support"
        },
        { id: 66, name: "Noah Garcia", dept: "Sales" },
        {
          id: 77,
          name: "Isabella Lee",
          dept: "Human Resources"
        },
        { id: 88, name: "James Smith", dept: "IT" },
        {
          id: 99,
          name: "Mia Johnson",
          dept: "Finance"
        },
        { id: 111, name: "Ethan Brown", dept: "Legal" }
      },
    
      /* Just sort the data */
      local!sortedAndPaged: todatasubset(
        local!employeeList,
        local!pInfo
      ),
      
      /* The wrap it into a DS */
      local!ds: a!dataSubset(
        data: local!sortedAndPaged.data,
        startIndex: local!pInfo.startIndex,
        batchSize: local!pInfo.batchSize,
        sort: local!pInfo.sort,
        totalCount: count(local!employeeList),
        identifiers: index(local!sortedAndPaged.data, "id", {})
      ),
    
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!gridField(
                  label: "Employee Directory",
                  data: local!ds,
                  columns: {
                    a!gridColumn(
                      label: "Name",
                      sortField: "name",
                      value: fv!row.name
                    ),
                    a!gridColumn(
                      label: "Department",
                      sortField: "dept",
                      value: fv!row.dept
                    )
                  },
                  selectable: true(),
                  selectionValue: local!selection,
                  selectionSaveInto: local!selection,
                  pagingSaveInto: local!pInfo
                )
              }
            )
          }
        )
      }
    )

Reply
  • +1
    Certified Lead Developer
    in reply to deepakrana77

    Directly storing the identifiers works like a charm!

    a!localVariables(
      local!selection: {},
      local!pInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 5,
        sort: a!sortInfo("name", true)
      ),
      local!employeeList: {
        {
          id: 11,
          name: "Sophia Turner",
          dept: "Marketing"
        },
        {
          id: 22,
          name: "Liam Brown",
          dept: "Operations"
        },
        {
          id: 33,
          name: "Emma Davis",
          dept: "Product Management"
        },
        {
          id: 44,
          name: "Oliver Martinez",
          dept: "Engineering"
        },
        {
          id: 55,
          name: "Ava Wilson",
          dept: "Customer Support"
        },
        { id: 66, name: "Noah Garcia", dept: "Sales" },
        {
          id: 77,
          name: "Isabella Lee",
          dept: "Human Resources"
        },
        { id: 88, name: "James Smith", dept: "IT" },
        {
          id: 99,
          name: "Mia Johnson",
          dept: "Finance"
        },
        { id: 111, name: "Ethan Brown", dept: "Legal" }
      },
    
      /* Just sort the data */
      local!sortedAndPaged: todatasubset(
        local!employeeList,
        local!pInfo
      ),
      
      /* The wrap it into a DS */
      local!ds: a!dataSubset(
        data: local!sortedAndPaged.data,
        startIndex: local!pInfo.startIndex,
        batchSize: local!pInfo.batchSize,
        sort: local!pInfo.sort,
        totalCount: count(local!employeeList),
        identifiers: index(local!sortedAndPaged.data, "id", {})
      ),
    
      {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!gridField(
                  label: "Employee Directory",
                  data: local!ds,
                  columns: {
                    a!gridColumn(
                      label: "Name",
                      sortField: "name",
                      value: fv!row.name
                    ),
                    a!gridColumn(
                      label: "Department",
                      sortField: "dept",
                      value: fv!row.dept
                    )
                  },
                  selectable: true(),
                  selectionValue: local!selection,
                  selectionSaveInto: local!selection,
                  pagingSaveInto: local!pInfo
                )
              }
            )
          }
        )
      }
    )

Children