Skip to main content
January 26, 2021
Solved

merging dictionaries

  • January 26, 2021
  • 5 replies
  • 0 views

I make a call to an integration and receive an output like above. I have a requirement where i need to append every dictionary that comes under cells with the corresponding row ID in the top and save it in table. how do i do that ?

Best answer by danny.verb

Gotcha, it looks like your top dictionary is a list of dictionary. No problem, you just need to create another outer loop.

a!localVariables(
   local!myDictionaries: {
      {
         id: 123456,
         fieldOne: Hello,
         fieldTwo: World,
         cells: {
            {
              columnId: 1,
              value: foo
            },
            {
              columnId: 2,
              value: bar,
            }
         }
      },
      {
         id: 123456,
         fieldOne: Hello,
         fieldTwo: World,
         cells: {
            {
              columnId: 1,
              value: foo
            },
            {
              columnId: 2,
              value: bar,
            }
         }
      }
   },
   local!newDictionaries: a!foreach(
      local!myDicionaries,
      a!localVarialbes(
        local!dict: fv!item,
        {
          id: local!dict.id,
          fieldOne: local!dict.fieldOne,
          fieldTwo: local!dict.fieldTwo,
          cells: a!forEach(
             local!dict.cells,
             {
                columnId: fv!item.columnId,
                value: fv!item.columnId,
                parentId: local!dict.id
             }
          )
       }
      )
   ),
   local!newDictionaries
)

5 replies

danny.verb
January 26, 2021

a!localVariables(
   local!myDictionary: {
     id: 123456,
     fieldOne: Hello,
     fieldTwo: World,
     cells: {
        {
          columnId: 1,
          value: foo
        },
        {
          columnId: 2,
          value: bar,
        }
     }
   },
   local!newDictionary: {
      id: local!myDictionary.id,
      fieldOne: local!myDictionary.fieldOne,
      fieldTwo: local!myDictionary.fieldTwo,
      cells: a!forEach(
         local!myDictionary.cells,
         {
            columnId: fv!item.columnId,
            value: fv!item.columnId,
            parentId: local!myDictionary.id
         }
      )
   },
   local!newDictionary
)

Here is a code example that should get you started. I also recommend using a!map() instead of a dictionary because it will preserve the type information

docs.appian.com/.../fnc_system_map.html

January 26, 2021

In my case Id's are in form of list. how do i change the code in such a way that first Id appends with the dictionary 

danny.verb
January 26, 2021

Gotcha, it looks like your top dictionary is a list of dictionary. No problem, you just need to create another outer loop.

a!localVariables(
   local!myDictionaries: {
      {
         id: 123456,
         fieldOne: Hello,
         fieldTwo: World,
         cells: {
            {
              columnId: 1,
              value: foo
            },
            {
              columnId: 2,
              value: bar,
            }
         }
      },
      {
         id: 123456,
         fieldOne: Hello,
         fieldTwo: World,
         cells: {
            {
              columnId: 1,
              value: foo
            },
            {
              columnId: 2,
              value: bar,
            }
         }
      }
   },
   local!newDictionaries: a!foreach(
      local!myDicionaries,
      a!localVarialbes(
        local!dict: fv!item,
        {
          id: local!dict.id,
          fieldOne: local!dict.fieldOne,
          fieldTwo: local!dict.fieldTwo,
          cells: a!forEach(
             local!dict.cells,
             {
                columnId: fv!item.columnId,
                value: fv!item.columnId,
                parentId: local!dict.id
             }
          )
       }
      )
   ),
   local!newDictionaries
)