web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Reg update a field using Plugins

(0) ShareShare
ReportReport
Posted on by 15

Hi Team,        (using Dynamics 365 Crm, Visual Studio 2017)

       I have two entity Account and B(Custom entity). and In the entity B has one lookup field (For this lookup field target entity is Account) ,Based on the selection of lookup field ; the other field of entity B should be  populate (ie. If I select any Account which one has some field a1,a2 then respectively value should come for field b1,b2 in entity B1). I want to do this "using Plugin".

        So, Please help me regarding this, i am new in Crm. Basically , i need business logic code for plugin.

 Thanks.

*This post is locked for comments

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    Instead of writing code in a plugin, you could do this with a workflow that is triggered on update of the lookup field on entity B, and updates entity B with the values from record A

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    You can do this using plugin but there are other ways to achieve this.

    You can create a workflow that triggers on the lookup field change and copies value from Account to fields on Entity B.

    Let us know if you still have to do this using plugin.

    Also let us know if you need any help in doing this via workflow

  • Suggested answer
    gupta.ambar2009@gmail.com Profile Picture
    797 on at

    Entity CustomEntity  =context.Inputparameters["Target"] as Entity;

    Entityreference Account =CustomEntity.getAttributevalue<EntityReference>("Account");

    Entity Account=service.retrive("Account",Account.id, new columnSet("field b1", "field b2") );

    //in your logic you can use it

    Customentity["field a1"] = Account["field b1"];

    Customentity["field a2"] = Account["field b2"];

    //after complete register the plugin in   "pre operation"

  • Suggested answer
    Pawar Pravin Profile Picture
    5,237 on at

    Hi Mani_ratname,

    In your situation you can use pre operation plugin. Please refer following code for reference:

    Entity _entity = (Entity)context.InputParameters["Target"];

    Guid LookupId = _entity.Attributes.Contains("lookupname") ? _entity.GetAttributeValue<EntityReference>("lookupname").Id : Guid.Empty;

    Entity EntityDate = service.Retrieve("entitylogicalname", LookupId, new ColumnSet(true);

    _entity.Attributes["attributelogicalname"] = //Pass value here;

    _entity.Attributes["attributelogicalname"] = //Pass value here;

    _entity.Attributes["attributelogicalname"] = //Pass value here;

    context.InputParameters["Target"] = _entity;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans