Skip to main content

Notifications

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
  • Kim Goethals Profile Picture
    5 on at
    RE: How to update a lookup field on lead

    I found it, thanks!

    The solution for us was:

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

  • Verified answer
    Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: How to update a lookup field on lead

    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
    RE: How to update a lookup field on lead

    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."

  • ACECORP Profile Picture
    1,589 on at
    RE: How to update a lookup field on lead

    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
    RE: How to update a lookup field on lead

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

  • Suggested answer
    ACECORP Profile Picture
    1,589 on at
    RE: How to update a lookup field on lead

    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. 

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 106

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

Overall leaderboard

Product updates

Dynamics 365 release plans