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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Handle Concurrency in Dynamics 365 9.0 online

(0) ShareShare
ReportReport
Posted on by 655

I am trying to implement optimistic concurrency for an entity. My approach is to register a plugin on pre update, retrieve the record and execute an Update request with the same row version as the record I retrieved before. But here, the issue is with infinite loop. Since the main operation is yet to take place, Is there a way that to set the concurrency behavior in the existing context so that I dont have to call Update Request and check depth every time. There are more plugins in the pipe line in the post update/pre update as well.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shantnu Sharma Profile Picture
    655 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    I am trying to see how can I do it with out using any custom field. MS provided an example from a console app instead of something from inside CRM (plugin/wf). The pipeline changes everything.

    To your other point, I guess the concurrency will exist even though we are in the pre-update because the update would already have been made before my actions lock the record. The only problematic area is calling UpdateRequest with in Pre-Update event. I checked for depth and got out of it but I need to ensure of all the plugin firing on pre or post update. Depth check everywhere it can go in infinite loop. I am still unsure about the behavior.

    Update

    So what I did was on Pre update - I registered the plugin and checked for concurrency if the row version matches. I also checked for depth in the same plugin so that it is not triggered when the Update Request is called with in the same plugin.

    If there are any other plugins called on the update of the attribute, make sure they are properly ordered for their execution and depth checks are in place.In existing systems all the plugin might require to be checked for depth again.

  • ashlega Profile Picture
    34,477 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    That's my question exactly. I would assume you need to get rowVersion in advance to be able to use it (you get the rowVersion, this is your starting point). Then you issue an update request for that rowVersion. In your scenario, you issue an update request, then you are getting the rowVersion.. But, since you are already in the pre-update at that moment, I think the record is, already, locked.. so there is no concurrency at that moment (there could be concurrency before, but you would need toe request a different rowVersion then). But maybe I'm missing something.

    To your point.. one workaround for the "loop" might be to create a custom field, and to only set it when you are making an update from the plugin. Then you just need to check if that attribute is in the "Target"

  • Shantnu Sharma Profile Picture
    655 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    Okay I get your point now. It helps in case of concurrency (your scenario won't apply here). Suppose we both open a record at the same time. At this moment, all the fields values are the same. now after sometime, you update it. Now, the value of the field has changed since I opened it. If I try to update the same field, system should tell me that the value has been updated since I opened the record and I need to refresh the record or some other message.

  • Shantnu Sharma Profile Picture
    655 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    I am storing the row version first thing in my pre-update and then enabling the concurrency behavior using the update request. The problem is not with the scenario when the update fails (if the user is modifying a record which was updated in background). But when everything is alright means the user is trying to update the record with latest data,then two update requests are called:

    1. User generated. 2 Plugin generated (Update Request). Here we encounter infinite loop in the pipeline.

    Have you ever used it? I want to preserve the functionality, whatever be the way, not necessarily mine.

  • ashlega Profile Picture
    34,477 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    I guess what I am trying to understand is how the plugin helps..

    If, at 1 PM, you get a record and store its rowVersion in-memory.

    At 1:15 another app updates that record

    At 1:30 PM, you decide to update it using the rowVersion from 1 PM..

    All's good, the update fails.

    But, if you don't store that rowVersion at 1 PM and just get it in the plugin at 1:30, how is it helping?

  • Shantnu Sharma Profile Picture
    655 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    The scenario is simple, I want to restrict the update if the record has been updated in the background.

    Yes, if the result is negative the pipe line will stay fine as none of the plugins will get executed. But what if the result is positive. There is one Update event raised because of the user action and other one with in the plugin. what happens in this scenario. It is going into infinite loop.

  • Shantnu Sharma Profile Picture
    655 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    May be I was not clear enough but I am trying to use optimistic currency here.

  • ashlega Profile Picture
    34,477 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    Not sure if there is a way to set concurrency behavior that late in the process..

    Actually, if you don't mind, could you share the scenario?

    If you are doing it that way, the rowversion you are looking at might be different from the row version for which you originally started the update? Also, if the plugin is synchronous, I'm assuming the record should get locked anyway once you are in pre-update, so other updates should not be able to come through..

  • Suggested answer
    Wayne Walton Profile Picture
    13,728 on at
    RE: Handle Concurrency in Dynamics 365 9.0 online

    Microsoft has native support for Optimistic Concurrency.  Just use their flags instead of rebuilding your own: msdn.microsoft.com/.../dn932125.aspx

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans