Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

One Plugin instance runs at time

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.

Categories:
  • Mahmoud Amr Profile Picture
    Mahmoud Amr 60 on at
    RE: One Plugin instance runs at time

    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 ?

  • Mahmoud Amr Profile Picture
    Mahmoud Amr 60 on at
    RE: One Plugin instance runs at time

    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 ?

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,198 User Group Leader on at
    RE: One Plugin instance runs at time

    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/

  • sardar ahmed Profile Picture
    sardar ahmed 520 on at
    RE: One Plugin instance runs at time

    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/.../

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,645 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans