0
votes

My mvc application is updating the status on a custom entity in CRM dynamics 2015. we have a plugin which gets triggered when we update a specific status. We are facing a concurrency issue here, when two different is trying to update the same status at a same time on the entity, the status gets updated twice and system fires the plugin twice.

I tried using in my MVC code but it gives an error. Seems like i cannot use it on custom entity

Portal.abcclaim obj= new Portal.abcclaim ();
                obj.Attributes["abcclaimreceiveddate"] = Convert.ToDateTime(DateTime.Now);
                obj.Attributes["abcdateclaimsubmitted"] = Convert.ToDateTime(DateTime.Now);
                obj.Attributes["abcmodifiedbycontact"] = new EntityReference(Portal.Contact.EntityLogicalName, loggedInId);
                obj.Attributes["abcstatus"] = new EntityReference(Portal.abc_status.EntityLogicalName, status);
                obj.Attributes["SuppressDuplicateDetection"] = false;
                obj.Id = objid;
                serviceProxy.Update(obj);

is there any other way to handle this?

1
Do you have duplicate detection rule for this custom entity? What’s the error?Arun Vinoth - MVP

1 Answers

0
votes

You should use dedicated request if you want to set request parameters. In yours case it will be UpdateRequest (https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.updaterequest?view=dynamics-general-ce-9).

var updateRequest = new UpdateRequest()
{
    Target = obj,
};
updateRequest["SuppressDuplicateDetection"] = false;

var response = (UpdateResponse)osvc.Execute(updateRequest);

But it doesn't look like duplicate detection will solve concurrency problems. You should check check how to use ConcurrencyBehavior parameter. You can read more about concurrency in Dynamics 365 in this MS docs article: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/optimistic-concurrency

Hope that helps.