Skip to main content
Brainy
Jul 16, 2024 4:49 AM UTC
Solved

Update a field based on indexing

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 

    venkatrea696188
    Inspiring
    Jul 17, 2024 4:01 AM UTC

    Wrap it inside tointeger() and isn't it in reverse?? You want to update local!X  and update why you are giving direct record field reference??

    a!update(
    local!X[record.name],
    wherecontains(tointeger(local!Y.id),tointeger(local!X[recordname.id])),
    local!Y.name)

    10 replies

    venkatrea696188
    Inspiring
    Jul 16, 2024 5:03 AM UTC

    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

    Brainy
    Jul 16, 2024 3:32 PM UTC

    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.

    konduruc733182
    Inspiring
    Jul 16, 2024 3:36 PM UTC

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

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

    rajt0005
    Known Participant
    Jul 16, 2024 1:56 PM UTC

    you can also use a!forEach function

    Brainy
    Jul 16, 2024 3:33 PM UTC

    how can I so this upon button click