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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

One Plugin instance runs at time

(1) ShareShare
ReportReport
Posted on by 60

Hello,

I have a problem that i wrote a plugin that fires on update an entity field.

This plugin has a part of the code that reads a numerical value from another entity, set it to a field in the entity, then increments it by 1 in its entity.

So that the next plugin fires will read the incremented value from that entity, and so on.

But, on updating multiple records at time, the plugin fires at the same time, and some of records took the same numerical value and it seems "from my opinion" the incrementing process and updating the field in the other entity is slowly compared to the generating updates of records.

I would like to lock the part of code that of reading and updating/incrementing that value, using something like (Lock, Semaphore, Mutex) .

How can i achieve this please ?

I'm using CRM online by the way.

Thank you vey much.

I have the same question (0)
  • sardar ahmed Profile Picture
    520 on at

    Hi Mahmoud

    You can use transactions to lock the counter entity. first update any dummy field and then read the sequence number and increment it. this will lock the counter entity and prevents other instance from reading it.

    Refer below url

    bettercrm.blog/.../

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hello,

    I faced the same scenario once. I was able to solve the problem by understanding exactly how a plugin runs. In fact, a plugin works within a transaction. You can use the transaction to lock your record by updating a dummy value. 

    You will find on this blog a complete explanation and an example implementation of the same design: https://bettercrm.blog/2017/05/11/making-use-of-transactions-in-dynamics-365-customer-engagement/

  • Mahmoud Amr Profile Picture
    60 on at

    Hello meelamri

    Thank you for your responsive reply.

    I have applied your solution and it works in blocking successfully.

    But not all records that the plugin fires on updating it were created (gives me error that  "The work order number must be unique"), the others are created and took a unique number.

    I have generated 34 records that on each of them the plugin should fires, only 6 of them took unique number, the others failed/error.

    Jobs.PNG

    How can i eliminate this please ?

  • Mahmoud Amr Profile Picture
    60 on at

    Hello sardar ahmed

    Thank you for your responsive reply.

    I have applied your solution and it works in blocking successfully.

    But not all records that the plugin fires on updating it were created (gives me error that  "The work order number must be unique"), the others are created and took a unique number.

    I have generated 34 records that on each of them the plugin should fires, only 6 of them took unique number, the others failed/error.

    5305.Jobs.PNG

    How can i solve this please ?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans