Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

Posted on by 185

Hi!

We have Dynamics CRM Online SYNCHRONOUS plugin that throws error on update of Account records.

It is attached on PreUpdate event and queries all child records then update each child records. Our fetch only retieves 1000+ records but its still throwing timeout error.

Any suggestion to improve the plugin? Thanks!

*This post is locked for comments

  • JZot Profile Picture
    JZot 185 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    Hi Eran,

    Thanks for the reply.

    Yes you are correct. Accounts B, C, D, and E should be update when Account A was updated. What I meant was, let's say Account A was updated, then as mentioned Accounts B, C, D and E will also be updated. Then once Account B was updated, a plugin will trigger again to query its child (D and E) along with the logic (goes in parallel) of querying the child of Account A. Emphasis on the "goes in parallel".

    I've tried to update it in SYNC but for some reason other workflows and excel import was affected. Users might come back to us that those workflows/excel import are not working.

  • EranYaron Profile Picture
    EranYaron 140 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    Hey JZ,

    Not sure i'm following - wouldnt you want all of the accounts and child accounts to be updated?

    E.g.:

    Account A is Parent of Account B and of Account C

    Account B is parent of Account D and Account E

    Basedon my understanding of what you want, updating Account A Category to Logistics should flow down to all accounts - Accounts B and C because they are the direct child, and Acccounts D and E because there was an update on Account B - right?

    If you're happy for it to end with Accounts B and C (i.e. not go down to the next level) ensure that you are checking the context.Depth within the plugin.

    Also - seems a bit odd you're worried about this massive job running in the background, but running it in the foreground while the user actually has to wait is fine?

    Cheers,

    E

  • JZot Profile Picture
    JZot 185 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    I think changing it to SYNC will generate massive job and will be an issue as it seems there is some looping on my code. Basically because the plugin was triggered on update of Account entity and the actual logic of plugin is its updating as well the child records hence the looping.

    Ex.

    "Category" lookup field of "Customer ABC" was updated to "Logistics". Plugin will query all child records of "Customer ABC" and will update the same "Category" and set all to "Logistics".

    Now when the plugin updated the child records, plugin was triggered again since it is attached on update event. And the loop goes on and on and on.

    Can someone suggest we how do we usually implement plugins whenever it is triggered and update the same entity at the same time?

  • Suggested answer
    EranYaron Profile Picture
    EranYaron 140 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    In that case, switch it to be async, no other way to update over 1,000 records as part of a sync pipeline...

  • JZot Profile Picture
    JZot 185 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    Hi Eran,

    I am already using ExecuteMultipleRequest but still no luck.

  • Suggested answer
    EranYaron Profile Picture
    EranYaron 140 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    Hey JZ,

    It seems that the issue you are seeing is because of the amount of records being updated.  Sync Plugins (or Sync Workflows) have a hard limit of 2 minutes to execute, and it looks like updating over 1,000 account records is taking more than 2 minutes.  As a rule of thumb a single CRM Org Service can process about 5-10 record updates per second - depends how you send the request, how much info is in there, etc.  That means that in the best case scenario, from a plugin you would be able to update up-to 1,200 records.  If anything is not working perfectly, that number may reduce to around 600 records....

    One think you can do is try to use an ExecuteMultipleRequest to maybe save some time...

    If that doesn't work, you should probably change the logic\structure of your code. Simplest way is to make this update Async...

    Good luck!

    E

  • JZot Profile Picture
    JZot 185 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    Hi Vipin!

    Thanks for the reply! I've tried following your blog but it seems the issue still persists on my end.

    Cam you please let me know if I miss anything? Thanks!

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    I didn't properly handle an infinite recursive loop in my code, so it was failing and there are was ExecuteMultiple which does not work well when dealing with such case.

    Please have a look at detail blog here- https://vjcity.blogspot.com/2019/04/couldnt-complete-execution-of-plug-in.html

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    I would be tempted to move this code to a Custom Workflow Activity and create a workflow to trigger on the event and see how this works. 2000 is not a lot of records but its not a perfect candidate for Sync process, so trying a workflow might help

  • JZot Profile Picture
    JZot 185 on at
    RE: Plugin error System.TimeoutException: Couldn’t complete execution of the plug-in within the 2-minute limit

    UPDATE: I've tried to update the plugin to ASYNC and used context.depth but seems not ideal in terms of performance as some of our workflow and excel import is taking so much time

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans