- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2024 10:40 AM
After discovering a couple workflows that stalled because approvals were not set properly, when looking in the Workflow Contexts table there are over 15,000 workflows still run all the way back to 2019. Some are for tickets that should be closed out, some are listed as preventative maintenance that are still running.
Should these be deleted? Should they be taking that long to run? (over a year?)
What would you do?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2024 10:58 AM
Hi @clktester ,
Please refer below thread:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0960722
The script below can be used to filter for specific active context records on the 'wf_context' table in order to bulk delete/cancel a large amount of active context records.
Rather than creating a list query manually, open 'wf_context' in list view and construct the desired filter. Right-click the end of the filter breadcrumb and click 'copy query.' Paste this into addEncodedQuery, ensuring the query is enclosed in either ' ' or " ".
- Navigate to Scripts - Background
- Paste the following text:
var w = new Workflow();
var now_GR = new GlideRecord('wf_context');
now_GR.addEncodedQuery(' ');
now_GR.query()
while (now_GR.next()) {
w.cancelContext(now_GR);
} - Click 'Run script'
Plz mark my solution as Accept, If you find it helpful.
Thanks & Regards,
Sumanth meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2024 11:04 AM
Hi there,
Deleted? Definitely not!
Investigate why they are still running. Most likely you can group those 15,000 active context into a few tens of different variants. Just look why they are still running, was it a bug in the workflow, a gap in the process, a technical issue, etc. Based on that decide what to do, perhaps cancelling the workflows and making sure the bug etc is fixed asap. Or do some workflows still have steps that need to be executed?
Also think of how to monitor this for the future. 15,000 is lukily a low number. Though for companies with larger numbers this will have consequences on manageability, performance, database footprint.
Though even when its a low number, you want to be on top of this. For example perhaps some workflows still were supposed to do a ton of steps which know never are executed or with an extreme delay.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2024 10:58 AM
Hi @clktester ,
Please refer below thread:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0960722
The script below can be used to filter for specific active context records on the 'wf_context' table in order to bulk delete/cancel a large amount of active context records.
Rather than creating a list query manually, open 'wf_context' in list view and construct the desired filter. Right-click the end of the filter breadcrumb and click 'copy query.' Paste this into addEncodedQuery, ensuring the query is enclosed in either ' ' or " ".
- Navigate to Scripts - Background
- Paste the following text:
var w = new Workflow();
var now_GR = new GlideRecord('wf_context');
now_GR.addEncodedQuery(' ');
now_GR.query()
while (now_GR.next()) {
w.cancelContext(now_GR);
} - Click 'Run script'
Plz mark my solution as Accept, If you find it helpful.
Thanks & Regards,
Sumanth meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2024 11:04 AM
Hi there,
Deleted? Definitely not!
Investigate why they are still running. Most likely you can group those 15,000 active context into a few tens of different variants. Just look why they are still running, was it a bug in the workflow, a gap in the process, a technical issue, etc. Based on that decide what to do, perhaps cancelling the workflows and making sure the bug etc is fixed asap. Or do some workflows still have steps that need to be executed?
Also think of how to monitor this for the future. 15,000 is lukily a low number. Though for companies with larger numbers this will have consequences on manageability, performance, database footprint.
Though even when its a low number, you want to be on top of this. For example perhaps some workflows still were supposed to do a ton of steps which know never are executed or with an extreme delay.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field