Map with variable key

Certified Senior Developer

Is it somehow possible to create a map or dictionary using variables for the keys? For example, is there some way for me to do something like a!map(localvar1:local!var2) to make a user generated map? Or maybe use a foreach loop over a 2d array to convert it to a map? 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Hi, I know it's late, but I thought it'd be good to capture the response here.

    You could use reduce with merge to achieve the desired outcome - not sure if all functions were available at the time you asked.

    a!localVariables(
      local!keys: { "keyOne", "keyTwo", "keyThree" },
      local!values: { 117, "Appian", now() },
      reduce(
        a!update,
        a!map(),
        merge(local!keys, local!values)
      )
    )

    Kudos to for the coming up with the solution!

Reply
  • 0
    Certified Associate Developer

    Hi, I know it's late, but I thought it'd be good to capture the response here.

    You could use reduce with merge to achieve the desired outcome - not sure if all functions were available at the time you asked.

    a!localVariables(
      local!keys: { "keyOne", "keyTwo", "keyThree" },
      local!values: { 117, "Appian", now() },
      reduce(
        a!update,
        a!map(),
        merge(local!keys, local!values)
      )
    )

    Kudos to for the coming up with the solution!

Children
No Data