Appending Map with keys and values from second map

Good day experts!  I am attempting to merge two maps and have gone thru many examples from the forum but can't seem to get those solutions to work for my use case.

I have two maps that have different key value pairs that I want to merge into one map.  The example in my code shows that the maps are related by participantId.  I was able to get the key and value for one of the keys in the queueMap to update into the participantMap.  However I am struggling with getting all of the keys and values in queueMap to update into the related particpantMap.

Here is my successful attempt at just getting the first key value from queueMap to update into participantMap:

a!localVariables(
  local!participantMap: {
    a!map(
      participantId: 3402,
      blockId: 881,
      policyNumber: "VF80U16350",
      policyEffectiveDate: fn!date(2023, 9, 25),
      dateOfBith: null,
      firstName: "Bill",
      lastName: " Johnson",
      middleInitial: "W",
      ssn: "123456789",
      genderRefId: 68,
      suffixRefId: 63,
      statusRefId: 1032
    ),
    a!map(
      participantId: 3401,
      blockId: 881,
      policyNumber: "VF80U16340",
      policyEffectiveDate: fn!date(2023, 9, 25),
      dateOfBith: fn!date(1996, 7, 4),
      firstName: "Robert",
      lastName: "Martinez",
      middleInitial: "J",
      ssn: "213456689",
      genderRefId: 69,
      suffixRefId: 66,
      statusRefId: 1093
    )
  },
  local!queueMap: {
    a!map(
      queueId: 3354,
      blockId: 881,
      participantId: 3402,
      appianGroupId: 58,
      assigneeUsername: "Karl.Seager@test.com",
      isActive: true,
      modifiedOn: fn!datetime(2024, 7, 18, 13, 31, 49, 0),
      lastAssignee: "",
      lastAssignedGroup: 25
    ),
    a!map(
      queueId: 3356,
      blockId: 881,
      participantId: 3401,
      appianGroupId: 58,
      assigneeUsername: "Karl.Seager@test.com",
      isActive: true,
      modifiedOn: fn!datetime(2024, 7, 18, 13, 31, 49, 0),
      lastAssignee: "",
      lastAssignedGroup: 25
    )
  },
  local!queueKeys: split(
    tostring(a!keys(index(local!queueMap, 1, {}))),
    ";"
  ),
  local!updatedMap: a!forEach(
    items: local!participantMap,
    expression: a!localVariables(
      local!pMap: fv!item,
      a!update(
        local!pMap,
        a!flatten(local!queueKeys[1]),
        index(
          index(
            local!queueMap,
            tostring(local!queueKeys[1]),
            {}
          ),
          wherecontains(
            local!pMap.participantId,
            local!queueMap.participantId
          ),
          {}
        )
      )
    )
  ),
  local!updatedMap
)

Here is the results of this code:

  Discussion posts and replies are publicly visible

  • +1
    Certified Senior Developer

    HI  ,

    You want all the keys and values in queueMap to be appened to corresponding participantMap. Please refer below code and is this what you expected.

    a!localVariables(
      local!participantMap: {
        a!map(
          participantId: 3402,
          blockId: 881,
          policyNumber: "VF80U16350",
          policyEffectiveDate: fn!date(2023, 9, 25),
          dateOfBith: null,
          firstName: "Bill",
          lastName: " Johnson",
          middleInitial: "W",
          ssn: "123456789",
          genderRefId: 68,
          suffixRefId: 63,
          statusRefId: 1032
        ),
        a!map(
          participantId: 3401,
          blockId: 881,
          policyNumber: "VF80U16340",
          policyEffectiveDate: fn!date(2023, 9, 25),
          dateOfBith: fn!date(1996, 7, 4),
          firstName: "Robert",
          lastName: "Martinez",
          middleInitial: "J",
          ssn: "213456689",
          genderRefId: 69,
          suffixRefId: 66,
          statusRefId: 1093
        )
      },
      local!queueMap: {
        a!map(
          queueId: 3354,
          blockId: 881,
          participantId: 3402,
          appianGroupId: 58,
          assigneeUsername: "Karl.Seager@test.com",
          isActive: true,
          modifiedOn: fn!datetime(2024, 7, 18, 13, 31, 49, 0),
          lastAssignee: "",
          lastAssignedGroup: 25
        ),
        a!map(
          queueId: 3356,
          blockId: 881,
          participantId: 3401,
          appianGroupId: 58,
          assigneeUsername: "Karl.Seager@test.com",
          isActive: true,
          modifiedOn: fn!datetime(2024, 7, 18, 13, 31, 49, 0),
          lastAssignee: "",
          lastAssignedGroup: 25
        )
      },
      local!queueKeys: a!keys(index(local!queueMap, 1, {})),
      local!updatedMap: a!forEach(
        items: local!participantMap,
        expression: a!localVariables(
          local!currentParticipantItem: fv!item,
          local!currentParticipantQueue: index(
            local!queueMap,
            wherecontains(
              tointeger(
                index(
                  local!currentParticipantItem,
                  "participantId",
                  null
                )
              ),
              tointeger(
                index(local!queueMap, "participantId", null)
              )
            ),
            null
          ),
          local!queueKeysValuesArray: a!forEach(
            items: local!queueKeys,
            expression: index(
              local!currentParticipantQueue,
              fv!item,
              null
            )
          ),
          a!update(
            fv!item,
            local!queueKeys,
            local!queueKeysValuesArray
          )
        )
      ),
      local!updatedMap
    )

  • 0
    Certified Associate Developer

    If you want to update, you can use a!update() function

  • Thank you so much Shanmathi!  This worked like a charm!  I was struggling with how to get the values array to line up with the keys that I wanted to add to the first map.