title: Loading records into Dynamics 365 through ADF
body: <p>I'm using the Dynamics connector in Azure Data Factory.</p>
  
  <h1>TLDR</h1>
  
  <p>Does this connector support loading child records which need a parent record key passed in? For example if I want to create a <code>contact</code> and attach it to a parent <code>account</code>, I upsert a record with a null <code>contactid</code>, a valid <code>parentcustomerid</code> GUID and set <code>parentcustomeridtype</code> to 1 (or 2) but I get an error.</p>
  
  <h1>Long Story</h1>
  
  <p>I'm successfully connecting to Dynamics 365 and extracting data (for example, the <code>lead</code> table) into a SQL Server table</p>
  
  <p>To test that I can transfer data the other way, I am simply loading the data back from the <code>lead</code> table into the <code>lead</code> entity in Dynamics.</p>
  
  <p>I'm getting this error:</p>
  
  <blockquote>
    <p>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'.</p>
  </blockquote>
  
  <p>As a test I removed <code>ownerid</code> from the list of source columns it loads OK.</p>
  
  <p>This is obviously a foreign key value.</p>
  
  <p>It raises two questions for me:</p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>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?</p></li>
  </ol>
  
  <p>How is this normally done through other API's, i.e. the web API?</p>
  
  <p>Is there an XRMToolbox addin that would help clarify?</p>
  
  <p>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.</p>
  
  <h1>EDIT 1</h1>
  
  <p>I realised that the <code>lead.ownertypeid</code> field in my source dataset is <code>NULL</code> (that's what was exported).  It's also NULL if I browse it in various Xrmtoolbox tools. I tried hard coding it to <code>systemuser</code> (which is what it actually is in the <code>owner</code> table against the actual owner record) but I still get the same error.</p>
  
  <p>I also notice there's a record with the same PK value in <code>systemuser</code> table</p>
  
  <p>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?</p>
  
  <h1>EDIT 2</h1>
  
  <p>I was getting a similar message for <code>msauto_testdrive</code> for <code>customerid</code>. </p>
  
  <p>I excluded all records with <code>customerid=null</code>, and got the same error.</p>
  
  <h1>EDIT 2</h1>
  
  <p><a href="https://help.scribesoft.com/scribeinsight/en/Subsystems/AdapterForDynamicsCRM/reference/customerid_and_customeridtype.htm" rel="nofollow noreferrer">This link</a> appears to indicate that I need to set <code>customeridtype</code> to 1 (Account) or 2 (Contact). I did so, but still got the same error.</p>
  
  <p>Also I believe I have the <a href="https://stackoverflow.com/questions/27373906/ms-crm-2013-attribute-parentcustomeridtype-must-not-be-null-if-attribute-parentc">same issue as this guy</a>. </p>
  
  <p>Maybe the ADF connector suffers from the same problem.</p>