Update a field based on indexing

Certified Associate Developer

I have two variables of list type, 

local!selecteddata: { id:1, name:test1, id:4,name:test4}.  

local!data:{id:1,name:test1,

                 id:2,name:test2,

                 id2,name:test3,

                 id4,name:test4

}

if I update the "name" fields of local!selecteddata,How do I index local!data and update the field "name" for ids : 1 and 4 . Any help is appreciated 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    a!localVariables(
      local!Y: {
        a!map(id: 1, name: "test5"),
        a!map(id: 4, name: "test6")
      },
      local!X: {
        a!map(id: 1, name: "test1"),
        a!map(id: 2, name: "test2"),
        a!map(id: 3, name: "test3"),
        a!map(id: 4, name: "test4")
      },
      a!update(
        local!X,
        wherecontains(local!Y.id, local!X.id),
        local!Y
      )
    )
    
    -------------------------------------------------------------
    
    a!localVariables(
      local!Y: {
        a!map(id: 1, name: "test7"),
        a!map(id: 4, name: "test8")
      },
      local!X: {
        a!map(id: 1, name: "test1"),
        a!map(id: 2, name: "test2"),
        a!map(id: 3, name: "test3"),
        a!map(id: 4, name: "test4")
      },
      a!update(
        local!X,
        "name",
        a!update(
          local!X.name,
          wherecontains(local!Y.id, local!X.id),
          local!Y.name
        )
      )
    )

    It can be achieved multiple ways. use Wherecontains() to index based on id

  • 0
    Certified Associate Developer
    in reply to venkat Avuluri

    thanks for the reply, is there a way , I can do this inside a button. my requirement is upon button click , I need to update.

  • 0
    Certified Senior Developer
    in reply to kowsalyavijayan

    you can use the same what Venkat has mentioned in the buttons saveInto parameter.

    a!save(target: local!data,value: a!update()) 

  • 0
    Certified Associate Developer
    in reply to Konduru Chaitanya

    tried this, but local!data lost rows with id 2 and id 4, because we are saving only two updated rows into this variable)

  • 0
    Certified Senior Developer
    in reply to kowsalyavijayan
    tried this, but local!data lost rows with id 2 and id 4, because we are saving only two updated rows into this variable)

    Yeah Update returns the result.. So need to careful with what you are indexing. Have a look into the below template

    a!localVariables(
      local!Y: {
        a!map(id: 1, name: "test5"),
        a!map(id: 4, name: "test6")
      },
      local!X: {
        a!map(id: 1, name: "test1"),
        a!map(id: 2, name: "test2"),
        a!map(id: 3, name: "test3"),
        a!map(id: 4, name: "test4")
      },
      {
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Button",
              style: "OUTLINE",
              saveInto: a!save(
                local!X.name,
                a!update(
                  local!X.name,
                  {
                    wherecontains(
                      tointeger(local!Y.id),
                      tointeger(local!X.id)
                    )
                  },
                  { local!Y.name }
                )
              )
            )
          },
          align: "START",
          marginBelow: "NONE"
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to venkat Avuluri

    works perfect for local variable , but for record type , it throws error a!localVariables(
    local!Y: {
    a!map(id: 1, name: "test5"),
    a!map(id: 4, name: "test6")
    },
    local!X: a!queryRecordType(
    recordType: 'recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test',
    fields: {},
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 100
    )
    ).data,
    {
    a!buttonArrayLayout(
    buttons: {
    a!buttonWidget(
    label: "Button",
    style: "OUTLINE",
    saveInto: a!save(
    local!X['recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{74a22d07-4f83-4cc6-b8e8-1d3ff4bb620e}name'],
    a!update(
    'recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{74a22d07-4f83-4cc6-b8e8-1d3ff4bb620e}name',
    {
    wherecontains(
    local!X['recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{0804dc2d-19ac-41c7-aee2-cae30a26dd96}id'],
    tointeger(local!Y.id)

    )
    },
    { local!Y.name }
    )
    )
    )
    },
    align: "START",
    marginBelow: "NONE"
    )
    }
    )

    error :

Reply
  • 0
    Certified Associate Developer
    in reply to venkat Avuluri

    works perfect for local variable , but for record type , it throws error a!localVariables(
    local!Y: {
    a!map(id: 1, name: "test5"),
    a!map(id: 4, name: "test6")
    },
    local!X: a!queryRecordType(
    recordType: 'recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test',
    fields: {},
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 100
    )
    ).data,
    {
    a!buttonArrayLayout(
    buttons: {
    a!buttonWidget(
    label: "Button",
    style: "OUTLINE",
    saveInto: a!save(
    local!X['recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{74a22d07-4f83-4cc6-b8e8-1d3ff4bb620e}name'],
    a!update(
    'recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{74a22d07-4f83-4cc6-b8e8-1d3ff4bb620e}name',
    {
    wherecontains(
    local!X['recordType!{a765be9a-3396-4105-8e82-56074696a931}LMS Test.fields.{0804dc2d-19ac-41c7-aee2-cae30a26dd96}id'],
    tointeger(local!Y.id)

    )
    },
    { local!Y.name }
    )
    )
    )
    },
    align: "START",
    marginBelow: "NONE"
    )
    }
    )

    error :

Children