Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

update lookup field

(0) ShareShare
ReportReport
Posted on by 10

string url = "">...........crm.dynamics.com";
var query = "/api/data/v9.1/pfna_test3s";

JObject pfna_test3 = null;

pfna_test3 = new JObject();
);

pfna_test3["pfna_name"] = "Test";
pfna_test3["pfna_lookup@odata.bind"] = "/pfna_test2s(GUID)";

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(url);
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);


HttpRequestMessage request1 = new HttpRequestMessage(HttpMethod.Post, url + query);
request1.Content = new StringContent(pfna_test3.ToString(),System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response1 = await httpClient.SendAsync(request1);

I am getting bad request .....

pfna_test3s is my table and it has a field titled 'pfna_lookup' which looks into pfna_test2s...

How can i have the create a record with lookup ... I can create with non look up field ... Please help

  • Suggested answer
    Bipin D365 Profile Picture
    28,977 Moderator on at
    RE: update lookup field

    Hi,

    Schema name of lookup field which you are passing is incorrect. I would recommend you to download Rest Builder tool and generate code from there to use in your c# code.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Suggested answer
    Nya Profile Picture
    29,060 on at
    RE: update lookup field

    Hi,

    Please refer to the following blog which may help you.

    Set Values of all Data Types using Web API in Dynamics CRM | Microsoft Dynamics 365 CRM Tips and Tricks (inogic.com)

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,125 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans