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

Reply
  • 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

Children