dynamics-crmazure-data-factorycommon-data-servicexrmtoolbox

Loading records into Dynamics 365 through ADF


I'm using the Dynamics connector in Azure Data Factory.

TLDR

Does this connector support loading child records which need a parent record key passed in? For example if I want to create a contact and attach it to a parent account, I upsert a record with a null contactid, a valid parentcustomerid GUID and set parentcustomeridtype to 1 (or 2) but I get an error.

Long Story

I'm successfully connecting to Dynamics 365 and extracting data (for example, the lead table) into a SQL Server table

To test that I can transfer data the other way, I am simply loading the data back from the lead table into the lead entity in Dynamics.

I'm getting this error:

Failure happened on 'Sink' side. ErrorCode=DynamicsMissingTargetForMultiTargetLookupField,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=,Source=,''Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Cannot find the target column for multi-target lookup field: 'ownerid'.

As a test I removed ownerid from the list of source columns it loads OK.

This is obviously a foreign key value.

It raises two questions for me:

  1. Specifically with regards to the error message: If I knew which lookup it needed to use, how can I specify which lookup table it should validate against? There's no settings in the ADF connector to allow me to do this.

  2. This is obviously a foreign key value. If I only had the name (or business key) for this row, how can I easily lookup the foreign key value?

How is this normally done through other API's, i.e. the web API?

Is there an XRMToolbox addin that would help clarify?

I've also read some posts that imply that you can send pre-connected data in an XML document so perhaps that would help also.

EDIT 1

I realised that the lead.ownertypeid field in my source dataset is NULL (that's what was exported). It's also NULL if I browse it in various Xrmtoolbox tools. I tried hard coding it to systemuser (which is what it actually is in the owner table against the actual owner record) but I still get the same error.

I also notice there's a record with the same PK value in systemuser table

So the same record is in two tables, but how do I tell the dynamics connector which one to use? and why does it even care?

EDIT 2

I was getting a similar message for msauto_testdrive for customerid.

I excluded all records with customerid=null, and got the same error.

EDIT 2

This link appears to indicate that I need to set customeridtype to 1 (Account) or 2 (Contact). I did so, but still got the same error.

Also I believe I have the same issue as this guy.

Maybe the ADF connector suffers from the same problem.


Solution

  • This is the ADF limitation with respect to CDS polymorphic lookups like Customer and Owner. Upvote this ADF idea

    Workaround is to use two temporary source lookup fields (owner team and user in case of owner, account and contact in case of customer) and with parallel branch in a MS Flow to solve this issue. Read more, also you can download the Flow sample to use.

    • First, create two temporary lookup fields on the entity that you wish to import Customer lookup data into it, to both the Account and Contact entities respectively
    • Within your ADF pipeline flow, you will then need to map the GUID values for your Account and Contact fields to the respective lookup fields created above. The simplest way of doing this is to have two separate columns within your source dataset – one containing Account GUID’s to map and the other, Contact.
    • Then, finally, you can put together a Microsoft Flow that then performs the appropriate mapping from the temporary fields to the Customer lookup field. First, define the trigger point for when your affected Entity record is created (in this case, Contact) and add on some parallel branches to check for values in either of these two temporary lookup fields

    enter image description here

    • Then, if either of these conditions is hit, set up an Update record task to perform a single field update, as indicated below if the ADF Account Lookup field has data within it