How to set lookup values through the Dynamics 365 web API – CRM Software Blog

 

 

When working with Microsoft Dynamics 365, setting lookup values via the Web API can be a common task and trick task. Lookups are essentially references to other records, and setting them correctly ensures data integrity and proper relationships between entities. In this blog post, we’ll walk through the steps to set lookup values using the Dynamics Web API and some of the quirks that go along with it.

Prerequisites

Before we dive in, make sure you have the following:


Access to a Dynamics 365 instance.



Necessary permissions to perform CRUD operations.



Basic understanding of RESTful APIs and JSON.

Step-by-Step Guide

1. Understand the Lookup Field Structure

Lookup fields in Dynamics 365 are represented as navigation properties. For example, if you have a contact entity with a lookup to an account, the lookup field is named parentcustomerid.

2. Get the GUID of the Target Record

To set a lookup value, you need the GUID of the record you want to reference. You can retrieve this GUID through a query to the Web API.

Example get request for a GUID;

GET [your_dynamics_organization_uri]/api/data/v9.2/accounts?$select=accountid&$filter=name eq ‘Nike’

3. Construct the JSON Payload

Once you have the GUID, you need to construct the JSON payload for your request. The lookup field is set using the @odata.bind annotation.

{ “parentcustomerid_account@odata.bind”: “/accounts(00000000-0000-0000-0000-000000000000)” }

Be careful! If you create a custom relationship between entities, than you must use the schema name of that lookup. Not the logical name. If you have a lookup from Employee to Manager and the schema name is dev_Manager, but the logical name is dev_manager, you will have to… (read full post on www.beringer.net)

 

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *