Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Account Update Plugin

Posted on by 40

Hi,

I am new to the Dynamics CRM 2013 plugins, 
On Account entity update I need to update the associated entity field.

Account entity I had a custom field new_Storename when I enter the value and save the record I need to update the associated records store name same as the account store name. On Store custom entity I have a new_name as the store name.

Account to Store entity I have 1: N relationship.

Thanks,

*This post is locked for comments

  • Suggested answer
    Alita Profile Picture
    Alita 40 on at
    RE: Account Update Plugin

    Plug in is working fine now.

    Updated the namespaces in my code.

  • Alita Profile Picture
    Alita 40 on at
    RE: Account Update Plugin

    T.I.A,

    Thank you for your quick response and logic.

    Thanks

  • Alita Profile Picture
    Alita 40 on at
    RE: Account Update Plugin

    Pravin,

    Thank you for the response and code

    When I debug the plug-in I am getting the values and updating the store name from account to associated store entity.

    But when I save the record on account entity I am getting the below error.

    Invalid argument.

    accountPlugin: System.ServiceModel.FaultException

  • Verified answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Account Update Plugin

    Hi Alita,

    Please refer below code:

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

           Entity _Store = new Entity("storeentitylogicalnamehere");

           string StoreName = Account.Contains("new_Storename") ? (string)Account.Attributes["new_Storename"] : string.Empty;

           if (StoreName != string.Empty)

           {

               EntityCollection StoreData;

               QueryExpression QueryStore = new QueryExpression()

               {

                   EntityName = "storeentitylogicalnamehere",

                   ColumnSet = new ColumnSet(true)

               };

               QueryStore.Criteria.AddCondition("accountId", ConditionOperator.Equal, Account.Id);

               StoreData = Service.RetrieveMultiple(QueryStore);

               if (StoreData.Entities.Count > 0)

               {

                   foreach (Entity Store in StoreData.Entities)

                   {

                       _Store.Attributes["storeentityfieldlogicalname"] = StoreName;

                       _Store.Id = Store.Id;

                       Service.Update(_Store);

                   }

               }

           }

    CapturePlugin.JPG

  • Verified answer
    T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Account Update Plugin

    QueryExpression query = new QueryExpression("name of associated entity");  

    query.ColumnSet.AddColumns("new_name");  

    query.Criteria.AddCondition("name of account field on store", ConditionOperator.Equal, "pass the guid of the account here");

    EntityCollection store = service.retrieveMultiple(query);

    Then you can update the new name field.

    [View:https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/tutorial-write-plug-in]

    You can use this as a reference

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans