Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Update primary entity in Ms crm plugin

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

How to update lookup field using entity.attribute.add(); method.I am writing plugin in work order entity.and I need to update city (lookfield) in work order form which is taking value from city in account form.we have accont lookup in work order entity.

  • LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Update primary entity in Ms crm plugin

    Hi partner,

    Look up field is a special object and we should use "EntityReference" instead of entity.attribute.add() to update the value.

    Entity tempOpp = new Entity();
    
    EntityReference lookupEntity = new EntityReference();
    
    lookupEntity.LogicalName = "account";
    
    lookupEntity.Id = new Guid(account_guid);
    
    lookupEntity.Name = account_name;
    
    tempOpp["parentaccountid"] = lookupEntity;// set value to look up field "parentaccountid"
    
    ServiceContext.UpdateObject(tempOpp);
    
    ServiceContext.SaveChanges();


    According to your description, you should get the accountid on your work order form first and then use this accountid to call webapi or xml to retrive the city value.

    In addition, I suggest that you could also use js code to set value to lookup field which can be more convenient.

    https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/archive/2017/09/20/how-to-get-and-set-a-lookup-field-using-javascript-in-dynamics-365

    Hope it helps.

    Best Regards,

    Leo

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans