Update specific field on specific index

Hello All,

I just want to know how can I update a specific field to a specific index? example is I have 3 list of items, and I only want to update the 2nd index first name to "Jerry" and not "Henry". I tried to use updatearray() but its only updating the whole data or I am missing something? 

{

index: 1,

name: "John",

lastName: "Doe"

},


{

index: 2,

name: "Henry",

lastName: "Doe"

},


{

index: 3,

name: "Jenny",

lastName: "Doe"

},

Looking forward to anyone reply. Thank you!

  Discussion posts and replies are publicly visible

Parents
  • Are you on 21.2? There's a great function that was recently released called a!update() that makes this pretty easy. The only tricky thing is that since you're updating a single value in a list of lists, you have to perform a!update() twice. Here's an example of how it works:

    a!localVariables(
      local!data: {
        { index: 1, name: "John", lastName: "Doe" },
        { index: 2, name: "Henry", lastName: "Doe" },
        { index: 3, name: "Jenny", lastName: "Doe" },
      },
      a!update(
        data: local!data,
        index: 2,
        value: a!update(
          data: index(local!data, 2, {}),
          index: "name",
          value: "Jerry"
        ),
      )
    )

Reply
  • Are you on 21.2? There's a great function that was recently released called a!update() that makes this pretty easy. The only tricky thing is that since you're updating a single value in a list of lists, you have to perform a!update() twice. Here's an example of how it works:

    a!localVariables(
      local!data: {
        { index: 1, name: "John", lastName: "Doe" },
        { index: 2, name: "Henry", lastName: "Doe" },
        { index: 3, name: "Jenny", lastName: "Doe" },
      },
      a!update(
        data: local!data,
        index: 2,
        value: a!update(
          data: index(local!data, 2, {}),
          index: "name",
          value: "Jerry"
        ),
      )
    )

Children