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
Hey Mike Schmitt , Stefan Helzle
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 ) ) } ) } ) } ) } )
you might need to consider handling converting the index to the primary key at the time of saving / retrieving row selections. in the old iteration of paging grid, we were actually able to pass in the identifiers manually (though in many other ways it was far more painful to use), but that went away as of the 19.2 (modern) version.
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 ) )*/ } ) } ) } ) } )
Ah in the chaotic identifier search I didn't thought the other way around. The OG wherecontains did the trick, thanks for your help!
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 ) } ) } ) } )
Thanks Stefan!