Workflow contexts executing longer than 5 minutes are getting cancelled. Any way to prevent that? (Max execution time exceeded)

Shibu2
Kilo Expert

find_real_file.png

 

find_real_file.png

 

 

It cancels while executing the workflow longer than 5 minutes. Is there a way for the workflow to wait until completion?

4 REPLIES 4

Manish Vinayak1
Tera Guru

Hi Shibu,

The transaction is getting cancelled by the system transaction quota rules. You could find the default out of the box transaction quota rules by navigating to the following module:

System Definition > Transaction Quota Rules

Transaction quotas allow you to define a quota policy for different types of transactions. A transaction quota cancels any transaction in violation of the policy and notifies the user of the cancellation.

Here are the links for documentation on Transaction Quotas:

https://docs.servicenow.com/bundle/london-platform-administration/page/administer/platform-performan...

https://docs.servicenow.com/bundle/london-platform-administration/page/administer/platform-performan...

https://docs.servicenow.com/bundle/madrid-platform-administration/page/administer/platform-performan...

https://docs.servicenow.com/bundle/london-platform-administration/page/administer/platform-performan...

You can turn on the debugging to see which quota rule is impacting your transaction. Then you can decide if you want to increase the quota transaction time.

But I would recommend trying to see why is your script taking so long to finish the job (more than 5 minutes seems a lot), maybe that "Run Script" could be optimized or triggered in a different way (Doing it asynchronously using script action and wait / using scheduled jobs to pick it, etc.)

Hope this helps!

Cheers,

Manish

The SN Nerd
Giga Sage
Giga Sage

Your options are:

  1. Optimize your script to run under 5 minutes
  2. Execute script outside of the workflow

Optimize your script to run under 5 minutes

Post your script and perhaps we can help you optimize it.

Execute script outside of the workflow

Execute the script outside the workflow in a Script Action triggered by an event.

For example, let's say your first Run Script is the culprit:

  • Create event 'Run Data Migration'
  • Create event 'Data Migration Complete'
  • Create WF activity 'Fire Event' - 'Run Data Migration', pass in current is a parameter
  • Create WF activity 'Wait for Event', wait for the event 'Data Migration Complete'
  • Create Script Action for Event, put your script in there instead
  • Delete your run script, it is now in an event
  • Use gs.eventQueue() in the Script Action to send completion event back to the workflow

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

DirkRedeker
Mega Sage

Hi

If you want to solve your issue, I recommend doing the following :

1) even if you learned, how to modify quota limits, I recommend NOT changing them. There is a good reason, why they exist and set up like that. It protects the overall system performance. 

2) obviously, you have long running tasks/scripts in the workflow. Workflows are not intended to act as batch queues, running long running batch scripts. Workflows are intended to ADVANCE processes. So, do NOT put long running scripts in the Script Actions of your workflow.

3) instead, put the long running steps to Script Actions (triggered by events, that you fire from within your workflow), or even better, by scheduled jobs. 

4) to wait for a condition in your workflow, I recommend to set some field as a flag, as soon as the scheduled job finishes, and that you implement a 'Wait for' Workflow Activity in your workflow.

That way, you moved the long running steps out of your workflow, and not getting in trouble with the quotas anymore. 

Let me know if that answered your question and mark my answer as correct and helpful, please. 

BR 

Dirk