Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Force Optimistic Concurrency using plugin

Posted on by 30

Hi all,

I'm trying to enforce the optimistic concurrency control for changes done via UI. To accomplish this I've created a plugin which is triggered in the Update message (Pre-operation stage) and sets the ConcurrencyBehavior setting to IfRowVersionMatches.

In theory, this should work smoothly but it actually does not. After some tests I've found that the RowVersion property is always null:

optimistic_5F00_concurrency.PNG


Without the RowVersion, CRM can't compare the entity being updated with the current version of the record so the validation is never triggered.

I know that this feature is something relatively new (MSND states "Optimistic concurrency behavior can only be set through an SDK call. There is presently no setting for it in a form of the Web application.") but I would expect that at least it should be possible to access the RowVersion from the plugin context and force this behaviour.

I've read about some issues related the RowVersion in the context of a (sandboxed) plugin so I'd like to know if this is a known problem or possible workarounds.

Thanks!

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Force Optimistic Concurrency using plugin

    I'm seeing this in CRM 2016 on-prem as well.  I have a plugin that generates a custom ID for an entity.  I have a non-sandbox, synchronous, pre-validation plugin that fires on-create.  It retrieves a 'last used ID' from another entity, increments it and saves back the updated 'last used ID'.  I was trying to use the RowVersion property to ensure another instance hadn't updated the 'last used ID' before I tried to update it, but RowVersion is empty every time.  I've double-checked the metadata to be sure that IsOptimisticConcurrencyEnabled is set to true for the entity that I'm trying to get RowVersion.

    My workaround was to lock the part of my plugin that retrieves, increments, and re-saves the last used ID as a critical section (C# lock statement).  Unfortunately, Fede, I don't think this applies to your situation, but maybe it will spark some ideas or help someone else that comes across this post.

  • tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Force Optimistic Concurrency using plugin

    Hi,

    Please let us know how it went, this may be some interesting feature

  • Fede Jousset Profile Picture
    Fede Jousset 30 on at
    RE: Force Optimistic Concurrency using plugin

    Hi again Pawel,


    Yes, I know that probably there's no nice answer/solution and that's why I was asking if this a know issue or a limitation. In previous releases there were some bugs related to the RowVersion from plugin context  (even using the Retrieve method) and it seemed possible that some of those issues are still there. Basically the problem is the one that you described, the RowVersion is not being passed to the Target and in my opinion that's something that should happen (it should be one of those "mandatory fields" of your message, it's not an attribute). Maybe it's just a matter of waiting for this feature to be fully implemented...

    In the meantime, I've found that it's possible to access the RowVersion from the client side using the following:

    Xrm.Page.data.entity.getRowVersion()

    I'll play a little bit to see if it's possible to implement a workaround using this.

    Thanks!

  • tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Force Optimistic Concurrency using plugin

    I can't see the relation here - ok CRM retrieves the entity on the form, but it does not pass this to the target. In target you have only fields you changed and some mandatory fields so it has no relationship with the entity that was retrieved for the form. If this would be so easy there would not be the statement that this is not working on the form (in the link you provided). I can't see any nice answer here, looks like this is not going to work in this scenario, maybe somebody else has some more ideas.

  • Fede Jousset Profile Picture
    Fede Jousset 30 on at
    RE: Force Optimistic Concurrency using plugin

    Hi Pawel, I'm trying to force the optimistic concurrency control for updates being done via User Interface so it does not make sense to retrieve the entity in the plugin (the RowVersion could be different). Actually, the Retrieve of the entity was performed by CRM when it loaded the form, so it doesn't seem too crazy to assume that the RowVersion attribute should be there.

  • Suggested answer
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: Force Optimistic Concurrency using plugin

    Hi

    Why don't you try post image?

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Force Optimistic Concurrency using plugin

    Hi,

    According to the documentation that you provided you have to retrieve the entity. You are not retrieving entity, you are using "Target" object in a plugin, which is not the same (target is passed to the plugin in the context and does not contain all the information that resides in the entity). Try to Retrieve this entity in this plugin - RowVersion should be filled.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans