Home » Dynamics » Optimistic Concurrency in Dynamics 365

Optimistic Concurrency in Dynamics 365

Text Widget

This is a text widget. The Text Widget allows you to add text or HTML to your sidebar. You can use a text widget to display text, links, images, HTML, or a combination of these. Edit them in the Widget section of the Customizer.

Introduction:

Very often, we need to retrieve an entity to update a field but due to concurrency issue, the entity is already updated, and we are stuck. In scenarios like this, we can use Optimistic Concurrency to determine whether an entity was modified since it was last retrieved!

Recently, while working with one of our applications, we faced the concurrency issue where we retrieved the data to be displayed on the form but, in some cases, the data was already modified through the plugin in the background. So, when the update action was fired, it was not executed on the latest data! So, we needed to check whether the data was modified since the last retrieval.

Using ‘Etag’ and ‘If-Match Header’ to detect modifications since the last retrieval:

Microsoft Dynamics 365 provides a weakly validating Property named ‘@odata.etag’ that is automatically returned along with each retrieved entity record as seen below;

Optimistic Concurrency in Dynamics 365This property is known as ‘ETag’ and is changed wherever modification is done on that entity record.

We used this property to check whether the data we have is the latest data. For this we added this ‘ETag’ value in the If-Match header in the update request as seen below;

Optimistic Concurrency in Dynamics 365If the data is not updated since we have last retrieved it, we get a 204 (No Content) status, and if the data is updated we get the response as seen below;

Optimistic Concurrency in Dynamics 365Based on the response, we can continue with the update operation or perform the retrieve action again to get the latest data.

Conclusion:

We can use the ETag property of the retrieved data and pass the same in the IF-Match header to check if the data we are working on is the latest data to avoid the concurrency issues.

Copy_clone Dynamics 365_CRM Records

from Microsoft Dynamics 365(CRM) Tips and Tricks http://bit.ly/2xvhQkU
via IFTTT


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: