Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

set lookup value when creating record

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi 

for set lookup value when creating record can use below sample code

Entity newEjraMasiryabiBazaryab = new Entity("new_ejra_masiryabi_bazaryab");

newEjraMasiryabiBazaryab["new_masir_montasb_bazaryab"] = new EntityReference("new_entsab_masir_bazaryab", new Guid( idEntsabMasirBazaryab.ToString()));
newEjraMasiryabiBazaryab["new_topic"] = "مسیر بازاریاب "+nameUser;
service.Create(newEjraMasiryabiBazaryab);

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: set lookup value when creating record

    Hi,

    Please try the code below.

    newEjraMasiryabiBazaryab["new_masir_montasb_bazaryab"] = new EntityReference("new_entsab_masir_bazaryab", idEntsabMasirBazaryab);

    Hope this helps.

  • Suggested answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: set lookup value when creating record

    Here is an example of some working code that I have got:

    Let me know if it helps

    Entity entity = (Entity)context.InputParameters["Target"];
    
    EntityReference modifiedby = (EntityReference)entity.Attributes["modifiedby"];
    
    
    Entity newAudit = new Entity("ppp_audithistory");
    newAudit.Attributes.Add("ppp_name", entity.LogicalName); //text field
    newAudit.Attributes.Add("ppp_guid", entity.Id.ToString()); //text field
    newAudit.Attributes.Add("ppp_user", new EntityReference("systemuser", modifiedby.Id));//Lookup field
    newAudit.Attributes.Add("ppp_date", entity["modifiedon"]); // Lookup field
    service.Create(newAudit);
  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: set lookup value when creating record

    Hi

    It looks correct.

    What error you are getting?

    Check idEntsabMasirBazaryab has a valid value (it should be an existing record of new_entsab_masir_bazaryab entity).

    If idEntsabMasirBazaryab is already a GUID value, then you do not need to convert to string and then convert back to GUID again.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans