merging dictionaries

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 ?

  Discussion posts and replies are publicly visible

Parents
  • 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

  • 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 

  • 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
    )

Reply
  • 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
    )

Children