Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Lookup field

Posted on by Microsoft Employee

Hi Guys,

I'm using webservices to create records in opportunity entity,

There are alot of lookup fields

How can I sue them in the code 

and wht does this mean?

         account.Attributes["????"] = new EntityReference("????", new Guid("b90240ad-2d0a-e511-80df-0a2032eda900"));

Thx alot

*This post is locked for comments

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: Lookup field

    account.Attributes["????"] : Here you need to specify the name of field/attribute of CRM entity- in this case it will be the attrbute name on acconut entity.

    new EntityReference("????" : Here you need to provide the Logical Name of the entity whose Guid you are providing.

    So suppose you want to set owner of account to xyz user.

    so you will write

    account.Attributes["ownerid"] = new EntityReference("systemuser", new Guid("b90240ad-2d0a-e511-80df-0a2032eda900"));

    Here the GUID need to be of the specific user who you want to set as owner.

    Thanks,

    PS

  • Ghetz Profile Picture
    Ghetz 2,983 on at
    RE: Lookup field

     Off Topic when responding to another post.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Lookup field

    Hi,

    Consider an example. You have a lookup field to Account called parentaccountid in the Opportunity form. So If I am creating a record of opportunity, then the code to set the value of lookup field should be as follows.

    Entity opportunity = new Entity("opportunity");
    opportunity.Attributes["parentaccountid"] = new EntityReference("account", new Guid("b90240ad-2d0a-e511-80df-0a2032eda900"));

    b90240ad-2d0a-e511-80df-0a2032eda900 is the guid of the account record.

    Hope this helps. 

  • Suggested answer
    jlattimer Profile Picture
    jlattimer 24,558 on at
    RE: Lookup field

    Example:

    account.Attributes["parentaccountid"] = new EntityReference("account", new Guid("b90240ad-2d0a-e511-80df-0a2032eda900"));

    account.Attributes["field logical name"] = new EntityReference("entity logical name", new Guid("b90240ad-2d0a-e511-80df-0a2032eda900"));

    This would set the Parent Account field on an Account record to another Account.

    Entity Reference is a way of creating a link to another record. It needs to be a complex type because you need the entity type and id to get back to a specific 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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans