Issue with Selection in the read-only grid

Certified Associate Developer

Hi,

I have Selectable Read-only grid and when I select few rows and click on select button a review grid will appear on the next page with the selected rows. Now I have an EDIT button which takes me to the previous page to select/de-select the rows, then here comes the issue that all the previous selection of the rows are getting removed.

The EDIT button doesn't have anything to remove the selection.

I'm not able to figure out what the issue is.. Can someone please help.

This is my code for the selectable grid and review grid. 

a!localVariables(
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: cons!RGRACSLBL_BATCHSIZE_5
  ),
  local!selectedBDLMAgreementActivities: if(
    not(
      or(
        rule!APN_isBlank(ri!BWELSelectedIds),
        rule!APN_isEmpty(ri!BWELSelectedIds)
      )
    ),
    index(
      ri!veevaResults.data,
      wherecontains(
        touniformstring(ri!BWELSelectedIds),
        touniformstring(index(ri!veevaResults.data, "id", {}))
      ),
      {}
    ),
    {}
  ),
  local!selectedRowDetails,
  local!selectedRow,
  {
    a!sectionLayout(
      label: if(
        ri!readOnly,
        "Review BDLM Multi Agreement Activity",
        "Select BDLM Multi Agreement Activity"
      ),
      contents: {
        a!localVariables(
          local!selectedActivities: todatasubset(
            local!selectedBDLMAgreementActivities,
            local!pagingInfo
          ),
          {
            if(
              ri!readOnly,
              {
                a!gridField(
                  label: "",
                  data: local!selectedActivities,
                  columns: {
                    a!gridColumn(
                      label: "Multi Agreement Activity Name",
                      value: a!richTextDisplayField(
                        value: a!richTextItem(
                          text: index(fv!row, "name__v", {}),
                          link: a!forEach(
                            items: fv!row,
                            expression: a!safeLink(
                              label: index(fv!item, "name__v", {}),
                              uri: rule!RGRACSLBL_createBDLMAgreementUrlId(
                                baseURL: index(
                                  cons!RGRACSLBL_VEEVA_BASE_URL,
                                  cons!RGRACSLBL_ENVIRONMENT_CURRENT
                                ),
                                agreementId: index(fv!item, "id", {})
                              )
                            )
                          )
                        )
                      )
                    ),
                    a!gridColumn(
                      label: "Product Name",
                      value: index(fv!row, "product__crname__v", {})
                    ),
                    a!gridColumn(
                      label: "Activity Type",
                      value: index(fv!row, "object_type__name__v", {}),
                      align: "START"
                    ),
                    a!gridColumn(
                      label: "Created By",
                      value: index(fv!row, "created_by__v", {})
                    ),
                    a!gridColumn(
                      label: "Created Date",
                      value: a!forEach(
                        items: rule!RGRACSLBL_merckDateFormat,
                        expression: todate(index(fv!row, "created_date__v", {}))
                      )
                    )
                  },
                  
                  pagingSaveInto: local!pagingInfo
                  
                  
                )
              },
              a!localVariables(
                local!veevaResults: cast(
                  a!listType(
                    typeof(
                      'type!{urn:com:appian:RGRACSLBL}RGRACSLBL_BDLMProductAgreements'()
                    )
                  ),
                  ri!veevaResults.data
                ),
                a!gridField(
                  label: "",
                  data: local!veevaResults,
                  columns: {
                    a!gridColumn(
                      label: "Multi Agreement Activity Name",
                      value: a!richTextDisplayField(
                        value: a!richTextItem(
                          text: index(fv!row, "name__v", {}),
                          link: a!forEach(
                            items: fv!row,
                            expression: a!safeLink(
                              label: index(fv!item, "name__v", {}),
                              uri: rule!RGRACSLBL_createBDLMAgreementUrlId(
                                baseURL: index(
                                  cons!RGRACSLBL_VEEVA_BASE_URL,
                                  cons!RGRACSLBL_ENVIRONMENT_CURRENT
                                ),
                                agreementId: index(fv!item, "id", {})
                              )
                            )
                          )
                        )
                      )
                    ),
                    a!gridColumn(
                      label: "Product Name",
                      value: index(fv!row, "product__crname__v", {})
                    ),
                    a!gridColumn(
                      label: "Activity Type",
                      value: index(fv!row, "object_type__name__v", {}),
                      align: "START"
                    ),
                    a!gridColumn(
                      label: "Created By",
                      value: index(fv!row, "created_by__v", {})
                    ),
                    a!gridColumn(
                      label: "Created Date",
                      value: a!forEach(
                        items: rule!RGRACSLBL_merckDateFormat,
                        expression: todate(index(fv!row, "created_date__v", {}))
                      )
                    )
                  },
                  pageSize: 5,
                  
                  selectionValue: local!selectedRow,
                  selectionSaveInto: {
                    local!selectedRow,
                    a!save(
                      local!selectedRowDetails,
                      append(local!selectedRowDetails, fv!selectedRows)
                    ),
                    a!save(
                      local!selectedRowDetails,
                      remove(
                        local!selectedRowDetails,
                        wherecontains(fv!deselectedRows, local!selectedRowDetails)
                      )
                    ),
                    a!save(
                      ri!BDLMAgreementActivity,
                      todatasubset(local!selectedRowDetails,local!pagingInfo)
                    )
                  },
                  
                  
                  
                  selectable: true,
                  shadeAlternateRows: true
                )
              )
            ),
            
          }
        )
      },
      showWhen: ri!search
    )
  }
)

This is my code for the EDIT button.

a!buttonWidget(
                    label: cons!RGRACSLBL_UA_EDIT,
                    value: cons!RGRACSLBL_UA_BACK,
                    saveInto: {
                      local!userAction,
                      a!save(ri!userAction, save!value),
                      a!save(local!saveDraftClicked, false),
                      a!save(local!skipSave, false),
                      a!save(ri!loggedInUser, local!loggedInUser),
                      a!save(ri!showEditButtonFlag, false),
                      a!save(local!showEditButtonFlag, false)
                    },
                    showWhen: local!showEditButtonFlag
                  ),

The grid is a child interface and it is being called in the parent interface as below

rule!RGRACSLBL_SC_BDLMAgreementsList(
                  readOnly: if(
                    or(
                      local!userAction = "review",
                      local!userAction = cons!RGRACSLBL_UA_SAVE_DRAFT
                    ),
                    true,
                    false
                  ),
                  BDLMAgreementActivity: local!BDLMSelectedAgreements,
                  search: local!search,
                  veevaResults: local!results,
                  BWELSelectedIds: local!BWELselectedIds,
                  
                )

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Need to see your code ,You Sure you don't have any refresh condition or any extra save which removes the value from the Selection variable  

  • As said by Venky, we need to see your code. 

    You might be missing the mapping between your two interfaces or something. 

  • 0
    Certified Senior Developer
    in reply to p2005
    The grid is a child interface and it is being called in the parent interface as below

    We need more context of this interface it seems to me  your handling total data using rule inputs of it. I'm gonna suggest you to cross check on click of Edit button  what is happening to local!selectedRow this variable is prime factor for your error (Sorry, I can't pinpoint it ).  I'm attaching a sample code of your scenario  have a look into it.

    a!localVariables(
      local!Data: {
        a!map(
          id: 1,
          Name: "Suresh Raina",
          Age: 38,
          Team: "CSK"
        ),
        a!map(id: 2, Name: "MS Dhoni", Age: 42, Team: "CSK"),
        a!map(
          id: 3,
          Name: "Rohit Sharma",
          Age: 38,
          Team: "MI"
        ),
        a!map(
          id: 4,
          Name: "Virat Kohli",
          Age: 37,
          Team: "RCB"
        ),
        a!map(
          id: 5,
          Name: "Zaheer Khan",
          Age: 44,
          Team: "DD"
        ),
        a!map(id: 6, Name: "Gambhir", Age: 42, Team: "KKR"),
        a!map(id: 7, Name: "Sachin", Age: 48, Team: "MI"),
        a!map(id: 8, Name: "Sehwag", Age: 44, Team: "PKBS")
      },
      local!Selected,
      local!selectionvalue,
      local!Page: 1,
      {
        a!cardLayout(
          contents: {
            a!gridField(
              label: "Read-only Grid",
              labelPosition: "ABOVE",
              data: local!Data,
              columns: {
                a!gridColumn(
                  label: "Name",
                  sortField: "Name",
                  value: fv!row.Name
                ),
                a!gridColumn(label: "Age", value: fv!row.Age),
                a!gridColumn(label: "Created By", value: fv!row.Team),
                
              },
              validations: {},
              selectable: true,
              selectionStyle: "CHECKBOX",
              selectionValue: local!Selected,
              selectionSaveInto: {
                local!Selected,
                a!save(
                  local!selectionvalue,
                  append(local!selectionvalue, fv!selectedRows)
                ),
                a!save(
                  local!selectionvalue,
                  difference(local!selectionvalue, fv!deselectedRows)
                )
              },
              
            ),
            a!buttonArrayLayout(
              buttons: {
                a!buttonWidget(
                  label: "Analyze",
                  saveInto: { a!save(local!Page, 2) },
                  disabled: a!isNullOrEmpty(local!Selected)
                )
              }
            )
          },
          height: "AUTO",
          style: "TRANSPARENT",
          marginBelow: "STANDARD",
          showWhen: local!Page = 1
        ),
        a!cardLayout(
          contents: {
            a!gridField(
              label: "Read-only Grid",
              labelPosition: "ABOVE",
              data: local!selectionvalue,
              columns: {
                a!gridColumn(
                  label: "Name",
                  sortField: "Name",
                  value: fv!row.Name
                ),
                a!gridColumn(label: "Age", value: fv!row.Age),
                a!gridColumn(label: "Created By", value: fv!row.Team),
                
              },
              
            ),
            a!buttonArrayLayout(
              buttons: {
                a!buttonWidget(
                  label: "Go home",
                  saveInto: { a!save(local!Page, 1) },
                  
                )
              }
            )
          },
          height: "AUTO",
          style: "TRANSPARENT",
          marginBelow: "STANDARD",
          showWhen: local!Page = 2
        ),
        
      }
    )