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 :
Microsoft Dynamics CRM (Archived)

How to set the value of [Lookup] in c#

(0) ShareShare
ReportReport
Posted on by

i am facing difficulty in setting the value of the Lookup in CRM using c#

i am using below code 

public string CreateContact()
{
HttpClient httpClient = apiRequest.ConnectToCRM();

JObject contact1 = new JObject { { "firstname", "Peter" }, { "lastname", "Parker" }, { "annualincome", 90000 }, { "emailaddress1", "peter.parker@gmail.com" },{ "customertypecode",3} };

//Option2
contact1["jobtitle"] = "Business Analyst";
/* contact1["parentcustomerid"] = Convert.ToString(id);*//*new EntityReference("account", guid);*/
WebApiRequestStatus createStatue = apiRequest.CreateRecord(httpClient, contact1, "contacts");
return createStatue == WebApiRequestStatus.RecordCreated ? "Record has been created successfully" : "Failed to create a record. Please check the portallog table for more information";
}

please help me out how to fix it.

*This post is locked for comments

I have the same question (0)
  • Rawish Kumar Profile Picture
    13,758 on at

    Hi Shashikant,

    please try below :

    contact1["parentcustomerid@odata.bind"] = "/accounts(Id)";

    Id in string.

  • Community Member Profile Picture
    on at

    thanks for your reply but i have already tried it and its not working except its showing following error message:

    System.NullReferenceException: 'Object reference not set to an instance of an object.

  • Verified answer
    Mansoor Sulaiman Profile Picture
    4,330 on at

    Hi,

    Please try as below.

    contact["parentcustomerid_account@odata.bind"] = "/accounts(81780845-8930-E611-9457-00155D189801)";

    Mansoor

  • Community Member Profile Picture
    on at

    Thanks a lot Mansoor its working now

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans