Skip to main content

Notifications

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.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: Merge service in Dynamics 365 C# plugin erroring out

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans