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

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    Nya Profile Picture
    29,060 on at

    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)

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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/

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 60 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 51

#3
Satyam Prakash Profile Picture

Satyam Prakash 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans