web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to update a lookup field on lead

(0) ShareShare
ReportReport
Posted on by 5

I want to create a new lead in MS Dynamics, but I have some issues with "address1_country". When I give a value for "address1_country" e.g. "BE", it doesn't update.

It seems to be a lookup field.

This is the body:

{
"firstname": "Test 123",
"lastname": "Test 456",
"cos_legaljustificationid@odata.bind":"/cos_legaljustifications(82ac0afd-b08c-e711-80d9-00155d141472)",
"cos_datasource": "181510001",
"address1_country" : "BE",
"address1_postalcode": "1234",
}
In the response, I get this:
"address1_country": null
What did I do wrong?
Schermafbeelding-2021_2D00_10_2D00_27-om-21.32.36.png
Schermafbeelding-2021_2D00_10_2D00_27-om-21.33.31.png
I have the same question (0)
  • Suggested answer
    ACECORP Profile Picture
    1,589 on at

    If you are using JavaScript to set the field value, you will need to get and use the Guid for the desired county, along with its name and the entity type as shown in the code below. 

    var CountryId = {desired record's guid};
    var CountryName = "Belgium";
    var CountryEType = "country";
    
    var lookupArray = new Array();
    lookupArray[0] = new Object();
    lookupArray[0].id = CountryId;
    lookupArray[0].name = CountryName;
    lookupArray[0].entityType = CountryEType;
    formContext.getAttribute("address1_country").setValue(lookupArray);

    If you are using a Power Automate Cloud Flow, C# Plugin, or a Traditional D365 Workflow, let me know and I can provide the details of how you need to implement this using the desired component. 

  • Kim Goethals Profile Picture
    5 on at

    We're using JSON to create a lead via Postman. So how would that work then?

  • ACECORP Profile Picture
    1,589 on at

    Postman inserts using D365 WebAPI correct?

    Assuming thats correct, and assuming you are using a custom entity for country and using a lookup field to it, you may need to do something like this: 

    JSONLead["new_countryid@odata.bind"] = "/new_countries(DFE54660-37CD-E511-80DE-6C3BE5A831DC)"
    

    If you are using a Global OptionSet for country, you will need to use the long integer value of the specific optionset value you want to set it to. 

  • Kim Goethals Profile Picture
    5 on at

    We already tried this:

    "cos_countryid@odata.bind":"/cos_countries(fb5de506-6f14-eb11-a812-000d3a201451)",

    "cos_countryId@odata.bind":"/cos_countries(fb5de506-6f14-eb11-a812-000d3a201451)",

    but without any luck.

    I always get these responses from Postman:

    "An undeclared property 'cos_countryid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values."

  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Please check below point.

    1. Check the schema name of country field update the request as
    "SchemaName@odata.bind":"/puralname(GUID)"

    2. if step 1 does not work the go with navigation property as described below link:
    https://carldesouza.com/the-trick-to-updating-custom-lookups-using-the-dynamics-365-web-api/

    Thanks,

    Pradeep.

    Please mark this as VERIFIED, if it helps,

  • Kim Goethals Profile Picture
    5 on at

    I found it, thanks!

    The solution for us was:

    "cos_CountryId@odata.bind":"/cos_countries(ff5de506-6f14-eb11-a812-000d3a201451)",

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 95

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans