How to Update, add new and delete record based on two objects

I have two objects… one object is main object and second object will have the data that is updating or deleting or adding.

Object 1:

[
  [
    {
      "party": [
        {
          "role": "Primary",         
          "partyId": 12,         
          "lastName": "Test",
          "roleType": "Test",
          "addresses": [
            {
              "address1": "test"
            }
          ],          
          "policyNos": "123456"
        },
        {
            "role": "Secondary",         
            "partyId": 12,         
            "lastName": "Test 4",
            "roleType": "Test 5",
            "addresses": [
              {
                "address1": "test"
              }
            ],          
            "policyNos": "123456"
          }
      ],
      "policyNos": "123456"
    },
    {
        "party": [
          {
            "role": "Primary",         
            "partyId": 12,         
            "lastName": "Test 1",
            "roleType": "Test 1",
            "addresses": [
              {
                "address1": "test"
              }
            ],          
            "policyNos": "234567"
          },
          {
              "role": "Secondary",         
              "partyId": 16,         
              "lastName": "Test 2",
              "roleType": "Test 2",
              "addresses": [
                {
                  "address1": "test"
                }
              ],          
              "policyNos": "234567"
            }
        ],
        "policyNos": "234567"
      }
  ]
]

Object2:

[
    {
        "role": "Primary",
        "partyId": 12,
        "lastName": "Test",
        "roleType": "Test",
        "addresses": [
            {
                "address1": "test"
            }
        ],
        "policyNos": "123456"
    }
]

Here, PartyId is the Unique value… how can I insert Object 2 into Object 1? can you please help me?

How to delete party record based on partyId from the object1 ?

How to add new party(will not have partyId) to the object1 ?

Can someone please help me with this ?

Thanks,
Narendra

Hi @Narendra! When you say insert Object 2 into Object 1, what should the expected output be? Are you trying to update everywhere where partyId is equal to 12 or are you trying to append it to the array?

Hi @ismaen,
Update: Need to update everywhere where partyId is equal to 12.
Add New: If no partyId, need to append to the corresponding policy from object 1
Delete: Delete the corresponding PartyID record from the policy in Object 1.

Update Party ID

One way to do this is by using Data flows. I’ve set up my data flow to run a sub-data flow in order to update Object 1:

Set up your inputs

Loop to create an array that does not include objects where partyid=12

Append the object that you want to update to the array. You can find this UDF here.

pass the output at the end of the data flow

Run this data flow as a sub data flow using the “Run data flow data operation”

Delete Object by Party ID

Set up your inputs

filter array to see where party id is not equal to the key


output at the end of the data flow

Run this data flow as a sub data flow using the “Run data flow data operation”

Add New

Based on my understanding, you could probably use the append UDF from the Update Data flow in order to append an object to the original object. You’d have to add some conditionals though.

Heres the zip file with the data flows and UDFs to play around with!

Update_Party-2022-09-19T20_50_48.198Z-full.branch.zip (20.5 KB)

@ismaen, thank you again ! I looked at the solution and this is what exactly I am looking for. it is very helpful.
But the output seems not correct. “Party” tag is missing from the output. How can I add the “party” tag so that the output structure should be the same as object 1 structure.

ah gotcha. You can re-add it as a transform step after you append the object2:

But after looking at the JSON structure, are there supposed to be two keys that are policyNos.

Thanks @ismaen for helping to fix this problem.

1 Like