On gridRowLayout selection i am populating the selected grid data in local!selectedGridData which has the clientID value for selected row. From this local!selectedGridData, we need to update the clientID value to ri!clientDetails.clientID at selected index

Hi All,

On gridRowLayout selection i am populating the selected grid data in local!selectedGridData which has the clientID value for selected row. From this local!selectedGridData, we need to update the clientID value to ri!clientDetails.clientID at selected index on click on button.

Here local!selectedGridData and ri!clientDetails both are of array.

Please help with sample code, so that i will try once.

Thanking you

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Can you clarify:
    1. Is the selection single select or multi select
    2. is the client ID field editable or read-only in the grid
    3. what does the ri! have before the button click? is it already populated with all client details and IDs
    4. local! will be empty on page load, let's say we have 5 entries in grid and you select the 3rd entry, what's the exact req. here on button click

  • Hi Vinay,

    1. Is the selection single select or multi select
    Ans:  Multi Select

    2. is the client ID field editable or read-only in the grid
    Ans:  read-only in the grid

    3. what does the ri! have before the button click? is it already populated with all client details and IDs
    Ans: before button click ri!clientDetails will be empty. On click on button, we are populating the below example fields

    ri!clientDetails will have array of data like below:

    [1]
    id null
    name Test
    mobile 1234567890
    ClientID null

    [2]
    id null
    name Test2
    mobile 1234567893
    ClientID null

    [3]
    id null
    name Test3
    mobile 1234567895
    ClientID null

    [4]
    id null
    name Test4
    mobile 1234567898
    ClientID null

    [5]
    id null
    name Test5
    mobile 1234567899
    ClientID null


    4. local! will be empty on page load, let's say we have 5 entries in grid and you select the 3rd entry, what's the exact req. here on button click
    Ans: local!selectedGridData will be empty on page load, it will be populated based on selection of row. When we select 3rd entry the local!selectedGridData will be populated as below example:

    [3]
    id null
    name Test3
    mobile 1234567895
    ClientID 1029093978

     

    Thanks

  • +1
    Certified Senior Developer
    in reply to Sandeep

    Try this in saveInto for the button:

    a!forEach(
    items: local!selectedIndices,
    expression: a!save(
    ri!clients[fv!item].clientID,
    index(
    local!selectedClients,
    fv!index,
    "clientID",
    null
    )
    )
    )


    If you want, you can try it out my code in a sample interface:

    a!localVariables(
      local!selectedClients,
      local!items: cast(
        'type!{urn:com:appian:types:TS}Test_Clients?list',
        {
          {
            id: 1,
            name: "Test1",
            mobile: 123,
            clientID: 10
          },
          {
            id: 2,
            name: "Test2",
            mobile: 456,
            clientID: 20
          },
          {
            id: 3,
            name: "Test3",
            mobile: 789,
            clientID: 30
          },
          {
            id: 4,
            name: "Test4",
            mobile: 1234,
            clientID: 40
          },
          {
            id: 5,
            name: "Test5",
            mobile: 12345,
            clientID: 50
          }
        }
      ),
      local!selectedIndices: tointeger({}),
      a!formLayout(
        contents: {
          a!buttonArrayLayout(
            align: "START",
            buttons: {
              a!buttonWidget(
                label: "Update Local!",
                value: "Update",
                saveInto: {
                  a!save(
                    local!selectedClients,
                    index(local!items, local!selectedIndices, null)
                  )
                },
                disabled: count(local!selectedIndices) = 0
              ),
              a!buttonWidget(
                label: "Update ri!",
                value: "Update",
                saveInto: {
                  a!forEach(
                    items: local!selectedIndices,
                    expression: a!save(
                      ri!clients[fv!item].clientID,
                      index(
                        local!selectedClients,
                        fv!index,
                        "clientID",
                        null
                      )
                    )
                  )
                },
                disabled: count(local!selectedIndices) = 0
              )
            }
          ),
          a!gridLayout(
            headerCells: {
              a!gridLayoutHeaderCell(label: "ID", align: "RIGHT"),
              a!gridLayoutHeaderCell(label: "Name"),
              a!gridLayoutHeaderCell(label: "Mobile", align: "RIGHT"),
              a!gridLayoutHeaderCell(label: "Client ID", align: "RIGHT")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3)
            },
            rows: a!forEach(
              items: local!items,
              expression: {
                a!gridRowLayout(
                  id: fv!index,
                  contents: {
                    a!integerField(
                      value: fv!item.id,
                      readOnly: true,
                      align: "RIGHT"
                    ),
                    a!textField(value: fv!item.name, readOnly: true),
                    a!integerField(
                      value: fv!item.mobile,
                      readOnly: true,
                      align: "RIGHT"
                    ),
                    a!integerField(
                      value: fv!item.clientID,
                      readOnly: true,
                      align: "RIGHT"
                    )
                  }
                )
              }
            ),
            selectable: true,
            selectionValue: local!selectedIndices,
            /* Flatten the selected values so the result is easier to work with */
            /* when the select/deselect all option is used in an editable grid  */
            selectionSaveInto: a!save(
              local!selectedIndices,
              a!flatten(save!value)
            ),
            rowHeader: 2
          ),
          a!textField(
            label: "Selected Values",
            labelPosition: "ADJACENT",
            instructions: typename(typeof(local!selectedIndices)),
            value: local!selectedIndices,
            readOnly: true
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(label: "Submit", submit: true)
        )
      )
    )


    Test ri! default value:
    {
      {
        id: null,
        name: "Test",
        mobile: 1234567890,
        ClientID: null
      },
      {
        id: null,
        name: "Test2",
        mobile: 1234567893,
        ClientID: null
      },
      {
        id: null,
        name: "Test3",
        mobile: 1234567895,
        ClientID: null
      },
      {
        id: null,
        name: "Test4",
        mobile: 1234567898,
        ClientID: null
      },
      {
        id: null,
        name: "Test5",
        mobile: 1234567899,
        ClientID: null
      }
    }