Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set the value of [Lookup] in c#

    Thanks a lot Mansoor its working now

  • Verified answer
    Mansoor Sulaiman Profile Picture
    Mansoor Sulaiman 4,330 on at
    RE: How to set the value of [Lookup] in c#

    Hi,

    Please try as below.

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

    Mansoor

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set the value of [Lookup] in c#

    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.

  • Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: How to set the value of [Lookup] in c#

    Hi Shashikant,

    please try below :

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

    Id in string.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans