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 :
Microsoft Dynamics CRM (Archived)

Multiple Plugins on the same Event - only one is executed

(0) ShareShare
ReportReport
Posted on by 1,722

Hi all,

I created two plugins that should be fired on the post-update of an invoice. I considered this thread: https://community.dynamics.com/crm/f/117/t/242982 , especially what Shivaram Santosh wrote:

If you are creating multiple plugins for same entity, then follow these 3.

1) First differentiate Plugins to Async and Sync (Based on need of result),

2) Still you have multiple Synchronous Plugins then set execution order.

3) After that sometimes you might get infinite loop error because of these multiple plugins. If you face this kind of error, then use Context.Depth for prevent this kind of errors.

I have both plugins registered on the Post-Update-Event, one is synchronous, one asynchronous - so there shouldn't be a problem I thought. In my code I have the following lines:

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "invoice", new Action<LocalPluginContext>(GenerateInvoiceNumber)));

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "invoice", new Action<LocalPluginContext>(UpdateVATInDetails)));

And whatever I tried until now - only the first plugin registered here in code is executed - if I swap the lines, the other one is executed. I also set both Plugins to synchronous and set the execution order - no success.

Thanks in advance

Kathrin

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    I had this problem. Just create a function like GenerateInvoiceNumberAndUpdateVATInDetails which calls your 2 functions and then call  it :

    base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "invoice", new Action<LocalPluginContext>(GenerateInvoiceNumberAndUpdateVATInDetails)));

    I should work this way

  • Kathrin Falsett Profile Picture
    1,722 on at

    Hi Guillaume,

    this is exactly what I'm doing now - but not what I wanted to do ;-) I hoped I could split all my plugins to make it easy to enable/disable functionality by just enable or disable a plugin in the registration tool.

    Kathrin

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Since your registered events does not differentiate between one plugin or another, you would need to combine both of you registered events into one.

    Inside your event code, you can capture if your plugin is synchronous or asynchronous, and then split the logic that way:

    if (localContext.PluginExecutionContext.Mode == 0) // Sync

       GenerateInvoiceNumber(localContext);

    else if (localContext.PluginExecutionContext.Mode == 1) // Async

      UpdateVATInDetails(localContext)l

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans