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 :
Customer experience | Sales, Customer Insights,...
Answered

How to create Record with lookup field using web API ?

(0) ShareShare
ReportReport
Posted on by 105

Hi  Experts,

I'm trying to create record with lookup field on Phonecall entity using WEB API in JS.

Note : Master Entity is Custom entity,

Phonecall["new_DispositionId@odata.bind"] = "/new_dispositions(B3CF9252-0B8A-EA11-A811-000D3A3E13CE)";

here I'm using schema name of lookup field but still getting error,

If I exclude this filed then record will be create , and include this filed then getting error. 

please help me out this issue.

Thanks in Advance.

I have the same question (0)
  • Suggested answer
    Gilmeyer Profile Picture
    on at
  • Verified answer
    Vivek Viraj Profile Picture
    60 on at

    You need update the script to below and it shall work

    Phonecall["new_DispositionId_PhoneCall@odata.bind"] = "/new_dispositions(B3CF9252-0B8A-EA11-A811-000D3A3E13CE)";

    It seems there is recent update from Microsoft in Web API methods.

    Hope this solves your issue.....!

  • nil_wagh Profile Picture
    105 on at

    Thanks @vivek patil, I have added above suggestion and its working now. Record is created with lookup field.

  • JagsCRM Profile Picture
    10 on at

    Hi Experts

    I am struggling with the same but with c#..tried with all option available but getting bad request .

    string url = "https://....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(7bE10D2D2C-0DB7-43DE-A106-C99B0326F3CA)";

       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);

    Any thoughts of a possible mistake here ..Please help

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

    Hello,

    Have you verified your code by only setting the name field which is of Text type to make sure there is some error while setting lookup field?

    You can download Rest Builder tool on your instance to generate and check the correct field schema name. Details can be found below

    carldesouza.com/.../

    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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans