Construct ActivityParty JSON Values for Dataverse Activity Entity Migration

30 March 2022
KingswaySoft Team

It is a fairly big challenge in an ETL project when you need to migrate Dynamics 365 CE/CRM/CDS/Dataverse activity entity data due to the activityparty fields involved in the entity. We have a previous blog post where we covered the migration of activity entity records from one CDS/CRM/Dataverse instance to another, utilizing the out-of-box CDS/CRM source and destination component capabilities provided in our SSIS Integration Toolkit for Microsoft Dynamics 365 product. The process involved a very straightforward mapping from the source system to the target system, which does not require some extensive effort, since the source component output those activityparty fields in JSON format, which can be directly consumed by the downstream CDS/CRM destination component without the requirements of making further transformations or manipulations. The ETL development was straightforward with the assistance of the Text Lookup feature provided in the CRM/CDS destination component. However, there are cases where your source of migration is not actually a CDS/CRM instance but rather a database table from your legacy system, or it might be an offline CDS/CRM database that you don't have an easy way to properly attach/import back as a CDS/CRM organization. In either of such cases, you would have to develop a strategy to construct a similar activityparty JSON format so we can pass it to CDS/CRM destination components for writing purposes. 

In this blog post, we will show a solution that can read data from an offline CDS/CRM database to generate the JSON structure using the SQL FOR JSON clause, which then can be sent to a CDS/CRM destination component for writing purposes.

To begin with, the following screenshot shows a sample of our input data; this is a mimic of the activitypointer entity data in D365 CDS/CRM/CE/Dataverse instance. As you can see, for one activity record, there may be multiple associated activitypointer records. Taking the “603CA9FE-B0B7-4DD1-93F6-0F3C6DD2BB28” activity record as the example, there are 2 associated parties: one account record (the first row) and one contact record (the second row).

input data

Our objective is to construct the activityparty JSON data structure using a SQL query so that we can pass it to a CDS/CRM destination component in order to write to the partylist fields in the target CDS/CRM activity entity. Based on this requirement, we resort to the SQL FOR JSON and GROUP BY clauses to construct the JSON document, which ends up with a SQL query below. Essentially we are performing a self-join on the activitypointer entity, and each set of child rows is formatted as a JSON array before it is constructed as a JSON document.

SELECT activityid,
(SELECT regardingobjectid AS PartyId, regardingobjecttypecode AS Type 
   FROM activitypointer a 
   WHERE a.activityid=b.activityid 
   FOR JSON PATH
) AS activityparty
FROM activitypointer b
GROUP BY activityid

The above SQL query can be used in an OLE DB source, ADO.NET source, or our Premium ADO.NET source component to emit the proper result. In order to validate the source component's output, we may turn on Data Viewer after the source component so that we can see the data flow through the SSIS pipeline. The following screenshot shows the desired JSON output value after the source component:

JSON output value after the source component

Once we have the JSON activityparty ready, we can simply send the data to a CRM/CDS destination component's activityparty fields for writing. In the destination component, you can leverage the Text Lookup feature for those party list fields as necessary. What we have accomplished is an almost identical activity entity migration experience like a CDS/CRM source to a CDS/CRM destination migration. This strategy can be used for legacy db to CDS/CRM/Dataverse migration as well.

We hope this has helped. Please feel free to let us know if you have any further comments or suggestions.

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