Manipulate CRM ActivityParty Field Values

12 May 2020
KingswaySoft Team

In most integration and migration projects, there may arise a scenario where the format of specific data values does not match the source and target instances. In these situations, we need to manipulate the input data, which can be challenging when working with the JSON format of CRM's ActivityParty fields.

In this blog post, we discuss one approach to change the input values of ActivityParty (partylist) fields to match the target instance's requirements using some of the components included in our SSIS Productivity Pack.

ActivityParty (PartyList) field format

When working with an ActivityParty (partylist) field, the output of the CRM Source Component will be in a JSON format (when using v5.0 or later version of our SSIS Integration Toolkit for Microsoft Dynamics 365). This output would allow a single cell value to consist of a list of parties. For each party record in the JSON structure, there will be a PartyId, which is a GUID, a Name, which is the party's name, and a Type, which indicates the party's entity type. The following is a sample of such output consisting of an account record and a systemuser record.

[
    {
        "PartyId":"c2cb1adc-cec4-e311-80e0-7845c4c5c272",
        "Name":"ABC Inc.",
        "Type":"account"
    },
    {
        "PartyId":"61f78159-c1ce-441e-9eb4-e4c84206d89f",
        "Name":"Joe Smith",
        "Type":"systemuser"
    },
]

Also, we can use this format to assign values to an ActivityParty field using our CRM Destination Component. In many integration scenarios, the GUID values of records do not match between the Source and Target instances, or the GUID values are not available in the Source input data. In this case, if the name matches the Source and Target instance as well as the target lookup entity, then we can map the previously mentioned JSON structure directly to the ActivityParty field in the CRM Destination Component and configure the Text Lookup feature on that field.

Challenges When Editing ActivityParty Fields

There are some scenarios where even the Name field doesn't match the Source and Target instances. Even the Text Lookup operation would fail as it would not be able to find an exact match in the target instance. In these situations, some string manipulation might be needed to change the format of the name field or change the target lookup entity, if required. For instance, consider the following example where we have the format of the fullname of the systemuser entity to be "Lastname, Firstname". However, the target CRM instance might have the fullname field in the format of "Firstname Lastname". In this case, we need to change the format of the Name field for the Text Lookup operation to succeed.

[ 
{              
"PartyId":"00000000-0000-0000-0000-000000000000", 
"Name": "LastName01, FirstName01", 
"Type":"systemuser" 
}, 
{ 
"PartyId":"00000000-0000-0000-0000-000000000000", 
"Name":"LastName02, FirstName02", 
"Type":"systemuser" 
}
]

This could be challenging as the JSON format could be fairly complex to edit, and an SSIS expression by itself wouldn't be enough in this case. For instance, there could be different parties in the same JSON array, and you would need to change the format for all of them or just for one target entity, while the array could have a variable number of party members. Therefore, a more reliable and flexible approach is required to manipulate the values of the incoming ActivityParty values.

Editing the JSON Values of the ActivityParty Field

Our approach, in this scenario, would include three main steps.

  1. Parse the JSON structure into a tabular format work with the data values easily in the dataflow task.
  2. Change the format of the Name field or to change the target entity depending on our use case.
  3. Reconstruct the JSON structure to pass it to the CRM Destination component after the required modifications are completed.

In our example, we will use a Data Spawner to generate a test record that includes the ActivityParty JSON snippet we mentioned earlier, however, you can use any other Source component based on your integration scenario. It is important to note that we need to rely on a unique ID field in the source input data, which is going to be used to link the changed ActivityParty field back to the original input record.

The next step would be to use a Multicast component to take a second output of the input data and work on the JSON structure to change it into the desired format. Then, we use our JSON Extract component to parse the JSON structure into a tabular format. This way, we would have a record for each partylist member along with the upstream unique ID as shown below:

Visual Studio Data Flow - Editing the JSON Values of the ActivityParty Field

The following step is to use a Conditional Split component to change the format of the Name field for only the selected target entities we want to work with. In our current example, we are working with the systemuser entity, so that's what is going to be included in the expression in the Conditional Split component so that all other entities of partylist members can pass through unchanged. Then, we would use our Premium Derived Column component to change the format of the Name field, which is going to set the Firstname before the Lastname. The following expression is an example of how this can be done; however, further adjustments might be needed depending on your use case:

SubString( [Name], FindString( [Name], ", ", 1 )+2, Len( [Name]) ) +" " + SubString( [Name], 1, FindString( [Name], ", ", 1 )-1 )

At this point, we were able to change the format of the Name field successfully, and we can now reconstruct the JSON structure with the new values. To do so, we can use our JSON Merge component for this purpose. However, to able to link back each new ActivityParty field with its original input record, we will add the unique ID within the JSON structure itself. Then, on the output of the JSON Merage component, we would use another Premium Derived Column component to extract this ID field and completely remove it from the JSON structure to put it back in its standard form. Finally, we use a Premium Lookup component to link each new ActivityParty field to its input record from the Source component. So, the complete data flow design would be as follows:

Visual Studio Complete Data Flow Design - Editing the JSON Values of the ActivityParty Field

By executing the package, we see that the Name format has been successfully changed, and the JSON structure has been put together in its original format:

Visual Studio Complete Data Flow Design with new JSON

Closing Notes

This is one of the approaches to change the values inside of an ActivityParty field for a given use case. However, the same approach can be used with any other scenario which requires the manipulation of partylist members. The change would be in the SSIS expression used in the Premium Derived Column to accommodate the different requirements. The sample SSIS package we used in this blog post is available for download here. The package was created under SSIS 2017.

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags