Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Inserting Value in lookup field of Lead object via API

Posted on by

Hi,

I am using this to create https://disco.crm11.dynamics.com/XRMServices/2011/Discovery.svc Lead via API. The field lead["ss_country"] is lookup field so how can i insert value in this field. Can anyone help on the same please?

Below is my code

ServerConnection serverConnect = new ServerConnection();
ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

using (_serviceProxy = ServerConnection.GetOrganizationProxy(config))
{

_serviceProxy.EnableProxyTypes();
Entity lead = new Entity("lead");

lead["firstname"] = c.firstname;
lead["lastname"] = c.lastname;

lead["ss_country"] = null;



_lead1Id = _serviceProxy.Create(lead);

return _lead1Id.ToString();
}

*This post is locked for comments

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Inserting Value in lookup field of Lead object via API

    Hi Shivi,

    You can get the GUID of the record in several ways. See the link below.

    https://arunpotti.wordpress.com/2016/07/10/how-to-get-guid-of-the-record-in-crm-online/

    To get the logical name of the entity, go to Settings --> Customization --> Customize the System.

    Click on Entities in the sidebar and find the logical name of the entity under the column Name as shown below.

    54662.1.PNG

    Hope this helps.

  • Verified answer
    ShiviG Profile Picture
    ShiviG on at
    RE: Inserting Value in lookup field of Lead object via API

    I know this syntax. How to get the GUID of lookup field. My look field is coming from look values entity. So what will be the logical name for the same.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Inserting Value in lookup field of Lead object via API

    Hi ,

    Try with this-

    Sample code -

    lead.Attributes["lookupfieldid"] = new EntityReference("contact", contactId); //if lookupfieldid is pointing to contact entity

    In your scenario -

    lead.Attributes["ss_country"] = new EntityReference("countryentityname", GUID of lookup record);

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans