Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Workflow on Merged Rec...
Sales forum

Workflow on Merged Records

Posted on by 182

Hi,

We have merged couple of records (accounts) in Dynamics CRM. This event has marked the status reason to Inactive and has updated the MasterId and Merged flag.

We have created a new On-demand workflow to update the status reason of these records from Inactive to Merged. Attached is the screenshot of the workflow.

pastedimage1564635670408v1.png

The workflow is updating the status reason correctly which helps us in differentiating the merged records from deactivated ones. But the problem is, after the workflow is executed, masterid is updated back to NULL and Merged flag is set to 0. I guess, since the workflow is updating the status reason, the system considers it as a DEACTIVATE event rather than MERGE.

Is there a way to avoid this?

Appreciate your help!

Cheers

Categories:
  • Inogic Profile Picture
    Inogic 24,094 on at
    RE: Workflow on Merged Records

    This is an OOB behavior, i.e. when you try to change the status reason of deactivated account, it will clear both the field “masterid” and “merged” using an OOB workflow.

    Now simpler approach will be to change the default status reason of Status Reason field to “Merged” as when a merge event gets triggered it will select the default status reason against “Inactive” status. But using this approach may also affect normal deactivated accounts as well so using this approach is not feasible.

    So writing a plugin on merge message can retain the value of masterid and merged flag.

    Here is the sample code for the same.

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)

                    {

                        EntityReference masterEntity = (EntityReference)context.InputParameters["Target"];

                        Guid guidSubOrdinate = (Guid)context.InputParameters["SubordinateId"];

     

                        // Get Master record information. Specify the attributes which you want to retrieve

                        Entity entMasterAccount = service.Retrieve("account", masterEntity.Id,new ColumnSet("name","accountid"));

     

                        // Get Subordinate record information. Specify the attributes which you want to retrieve

                        Entity entSubOrdinateAccount = service.Retrieve("account", guidSubOrdinate, new ColumnSet(new string[] { "statecode", "statuscode", "merged", "masterid" }));

     

                        if(entSubOrdinateAccount!=null)

                        {

                            Entity mergedAcc = new Entity(entSubOrdinateAccount.LogicalName, entSubOrdinateAccount.Id);

                            //Change Status Reason

                            if(entSubOrdinateAccount.Contains("statuscode") && entSubOrdinateAccount["statuscode"]!=null)

                            {                           

                                mergedAcc["statuscode"] = new OptionSetValue(100000000);

                            }

                            //Re-Set Master Id

                            if(entSubOrdinateAccount.Contains("masterid") && entSubOrdinateAccount["masterid"]!=null)

                            {

                                mergedAcc["masterid"] = new EntityReference(entMasterAccount.LogicalName, entMasterAccount.Id);

                            }

                            //Re-Set Merge Flag

                            if(entSubOrdinateAccount.Contains("merged") && entSubOrdinateAccount["merged"]!=null)

                            {

                                mergedAcc["merged"] = true;

                            }

                         

                            if(mergedAcc!=null)

                            {

                                //Update Record.

                                service.Update(mergedAcc);

                            }

                        }

                    }

     

    Hope this helps.

     

    Thanks!

  • Suggested answer
    Nijos Profile Picture
    Nijos 1,672 on at
    RE: Workflow on Merged Records

    Hi,

    This is an out of the box behavior, you can try capturing masterid to another custom field from the same workflow before changing the status.

    Nijo

    Hope this helps

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... 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