Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Reg update a field using Plugins

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

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Reg update a field using Plugins

    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;

  • Suggested answer
    RE: Reg update a field using Plugins

    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
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Reg update a field using Plugins

    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

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Reg update a field using Plugins

    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

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