<turbo-stream action="update" target="wiki_card"><template>

<h1>Error 0x80040237: Duplicate Records and Missing References</h1>
<div class="trix-content"><p><strong>What this error means:</strong> Error code 0x80040237 is used by Dynamics 365 for multiple different scenarios. This error code is <strong>not officially documented by Microsoft</strong>, making it particularly challenging to troubleshoot. Use the <strong>HTTP status code</strong> and <strong>error message</strong> to determine which scenario you're facing.<br><br>Check the error details to identify your scenario:<br><br></p><p></p><figure class="attachment attachment--content"><table class="table table-bordered"><thead><tr><td>HTTP Status</td><td>Error Message</td><td>Scenario</td></tr></thead><tbody><tr><td>400 Bad Request</td><td>"key was not present in the dictionary"</td><td>Missing Lookup Reference</td></tr><tr><td>412 Precondition Failed</td><td>"matching key values already exists"</td><td>Alternate Key Duplicate</td></tr><tr><td>Various</td><td>"Cannot insert duplicate key"</td><td>Platform Duplicate Constraint</td></tr></tbody></table><figcaption class="attachment__caption"></figcaption></figure><br><br><p></p><h2>Scenario 1: Missing Lookup Reference</h2><p><br></p><ul><li><strong>Status Code</strong>: 400 Bad Request</li><li><strong>Error Message</strong>: "The given key was not present in the dictionary"</li><li><strong>What happened</strong>: You're trying to reference a record (in a lookup field) that doesn't exist in Dynamics 365.</li></ul><p><br>Example: { "name": "New Contact", "parentcustomerid@odata.bind": "/accounts(00000000-0000-0000-0000-000000000000)" } where the account with that GUID does not exist in D365 Sales.</p><h3>Common Causes - Scenario 1</h3><ul><li><strong>Lookup GUID is hardcoded incorrectly</strong> in your mapping.</li><li><strong>Source system has outdated GUIDs</strong> that were deleted in D365.</li><li><strong>Sync order issue:</strong> Child records syncing before parent records.</li><li><strong>Security permissions:</strong> Service account can't see the lookup record.</li><li><strong>Different business unit:</strong> Record exists but in a BU the user can't access.</li></ul><p><br></p><h2>Scenario 2: Duplicate Alternate Key</h2><p><br><strong>Status Code</strong>: 412 Precondition Failed<br><strong>Error Message</strong>: "A record with matching key values already exists"<br><strong>What happened</strong>: You're trying to CREATE a new record, but a record with the same alternate key value(s) already exists in D365.<br><br></p><h3>Common Causes - Scenario 2</h3><ul><li><strong>Re-syncing the same record</strong> from source system.</li><li><strong>Source system sends updates as new records.</strong></li><li><strong>Sync running multiple times</strong> on the same data.</li><li><strong>Using CREATE instead of UPSERT</strong> for transactional data.</li><li><strong>Alternate key defined but sync flow doesn't account for it.</strong></li></ul><h2>Scenario 3: Platform Duplicate Key</h2><p><br><strong>Status Code</strong>: Various<br><strong>Error Message</strong>: "Cannot insert duplicate key"<br><strong>What happened</strong>: You're trying to create a record that violates a platform-enforced unique constraint on the database table itself.<br><br></p><h3>Common Causes - Scenario 3</h3><ul><li><strong>Syncing the same price list multiple times</strong> without checking existence.</li><li><strong>Source system sends full price list</strong> instead of just changes.</li><li><strong>Multiple integrations</strong> creating prices for the same products.</li><li><strong>Manual prices created in D365</strong> that conflict with sync.</li><li><strong>UOM conversions</strong> creating duplicate entries with same base UOM.</li></ul></div>
</template></turbo-stream>

