Transform two arrays into a map where the first array is the key and the second is the value

Certified Associate Developer

Hi,

I am parcticing with the a!queryRecordType() function and I realized in return one field called identifiers where the primiary key is returned and I would like to know if I could transform it together with the data field into a map where the identifiers values are the keys and the data values are the values.

For example:

Having:

identifiers : {12,20}

 data : {"first value", "second value"}

Transform it into

{12: "first value",

20: "second value}

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Senior Developer

    Hello ,

    Please refer the below code. I hope this will help.

    a!localVariables(
      local!identifiers: { 12, 20 },
      local!data: { "first value", "second value" },
      {
        append(
          a!forEach(
            items: local!identifiers,
            expression: concat(
              fv!item,
              ": ",
              index(local!data, fv!index, null)
            )
          )
        )
      }
    )

    can you also try this,

    a!localVariables(
      local!identifiers: { 12, 20 },
      local!data: { "first value", "second value" },
      {
    
         a!flatten(
           a!forEach(
             items: local!identifiers,
             expression: {
               a!map(
                 identifier:fv!item,
                 data:index(local!data,fv!index,null)
               )
             }
           )
         )
       
      }
    )

Reply
  • +1
    Certified Senior Developer

    Hello ,

    Please refer the below code. I hope this will help.

    a!localVariables(
      local!identifiers: { 12, 20 },
      local!data: { "first value", "second value" },
      {
        append(
          a!forEach(
            items: local!identifiers,
            expression: concat(
              fv!item,
              ": ",
              index(local!data, fv!index, null)
            )
          )
        )
      }
    )

    can you also try this,

    a!localVariables(
      local!identifiers: { 12, 20 },
      local!data: { "first value", "second value" },
      {
    
         a!flatten(
           a!forEach(
             items: local!identifiers,
             expression: {
               a!map(
                 identifier:fv!item,
                 data:index(local!data,fv!index,null)
               )
             }
           )
         )
       
      }
    )

Children