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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Merge service in Dynamics 365 C# plugin erroring out

(0) ShareShare
ReportReport
Posted on by 70
0

I am attempting to merge contact records in CRM. The following is my code and works fine until the end line at var merged = (MergeResponse)service.Execute(merge); I have tracers in the original code and is definitely erroring out at that specific line.

// Create the target for the request.
var target = new EntityReference();

// Id is the GUID of the account that is being merged into.
// LogicalName is the type of the entity being merged to, as a string
var targetId = (Guid)master.Attributes["contactid"];
target.LogicalName = entity.LogicalName;

// Create the request.
var merge = new MergeRequest();

// SubordinateId is the GUID of the account merging.
merge.SubordinateId = (Guid)subordinates.Attributes["contactid"];
merge.Target = target;
merge.PerformParentingChecks = false;
tracer.Trace("\nMerging contact2 into contact1 and adding " + "\"test job title from plugin\" as job title");

// Create another contact to hold new data to merge into the entity.
// If you use the subordinate account object, its data will be merged.

var updateContent = new Entity();
updateContent.LogicalName = entity.LogicalName;
updateContent["jobtitle"] = "test job title from plugin";

// Set the content you want updated on the merged account
merge.UpdateContent = updateContent;
// Execute the request.
var merged = (MergeResponse)service.Execute(merge);

The following is the error:

Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] Message: An error occurred in TransformaniaMergeContactsPlugin.Detail: 421301f5-3f26-4eb9-a546-88a93ff52f33 -2147220891 d2p1:keyOperationStatus</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:int">0</d2p1:value> d2p1:keySubErrorCode</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:int">-2146233088</d2p1:value> d2p1:keyPlugin.ExceptionFromPluginExecute</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">Transormania.Plugins.TransformaniaMergeContactsPlugin</d2p1:value> d2p1:keyPlugin.ExceptionRetriable</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:boolean">false</d2p1:value> d2p1:keyPlugin.ExceptionSource</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">PluginExecution</d2p1:value> d2p1:keyPlugin.OriginalException</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">PluginExecution</d2p1:value> d2p1:keyPlugin.PluginTrace</d2p1:key> <d2p1:value xmlns:d4p1="">www.w3.org/.../XMLSchema" i:type="d4p1:string">Hello plugin In Master entity for each results Master: test | contact | 2325a10e-527e-e911-a81d-000d3a1d9cdc | Group ID: 00000001 Subordinate: Test | User | b01d0639-847d-e911-a81a-000d3a1f0599 | Group ID: 00000001 Master Guid: 2325a10e-527e-e911-a81d-000d3a1d9cdc Entity Logical Name: contact Subordinate Id: b01d0639-847d-e911-a81a-000d3a1f0599

Merging contact2 into contact1 and adding "test job title from plugin" as job title Before update content Merge Content: Microsoft.Xrm.Sdk.Entity</d2p1:value> An error occurred in TransformaniaMergeContactsPlugin. 2021-12-09T18:49:10.8671998Z false PluginExecution PluginExecution Hello plugin In Master entity for each results Master: test | contact | 2325a10e-527e-e911-a81d-000d3a1d9cdc | Group ID: 00000001 Subordinate: Test | User | b01d0639-847d-e911-a81a-000d3a1f0599 | Group ID: 00000001 Master Guid: 2325a10e-527e-e911-a81d-000d3a1d9cdc Entity Logical Name: contact Subordinate Id: b01d0639-847d-e911-a81a-000d3a1f0599

Merging contact2 into contact1 and adding "test job title from plugin" as job title Before update content Merge Content: Microsoft.Xrm.Sdk.Entity

I'm not seeing anything specific to what the error is and am running out of options. Any extra eyes will help.

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    It is very unclear by looking at the error message.

    Why don't you enable profile and debug your plugin?

    Another approach is to create small Console application and try to execute the same code by providing the hardcoded value for contact ids.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 60 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 51

#3
Satyam Prakash Profile Picture

Satyam Prakash 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans