Announcements
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.
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.
How can i solve this please ?
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.
How can i eliminate this please ?
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/
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
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156