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.
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
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!
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156