Creating single map from list of maps

Hi,

Can anyone help me with converting multiple map into single map,

example input: {a!map(),a!Map(),a!map()}

output{a!map()}

Help is appreciated

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to salmak2626

    How can you create a single map with duplicate keys?

    If you wish to modify the key names at run time then you can add additional logic after getting local!keys. 

    I have added an additional local!modifiedKeys in Stefan's code

    a!localVariables(
      local!maps: {
        a!map(alpha: "a"),
        a!map(beta: 2),
        a!map(beta: 3),
        a!map(gamma: "three"),
        a!map(gamma: "four"),
        a!map(gamma: "five")
      },
      local!keys: a!flatten(
        a!forEach(
          items: local!maps,
          expression: a!keys(fv!item)
        )
      ),
      local!modifiedKeys: a!forEach(
        items: local!keys,
        expression: a!localVariables(
          local!indexCount: count(
            wherecontains(
              tostring(fv!item),
              touniformstring(local!keys)
            )
          ),
          if(
            local!indexCount = 1,
            fv!item,
            concat(fv!item, fv!index)
          )
        )
      ),
      a!update(
        a!map(),
        local!modifiedKeys,
        a!forEach(
          items: local!maps,
          expression: index(fv!item, a!keys(fv!item), null)
        )
      )
    )

  • Thanks for the solution, I was able to use Stefan’s code and resolved my issue yesterday