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

Announcements

No record found.

News and Announcements icon
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,218 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 109 Super User 2026 Season 1

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 46 Most Valuable Professional

#3
NeerajPawar Profile Picture

NeerajPawar 39

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans