Workflow Contexts more than a year old?

clktester
Tera Contributor

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? 

2 ACCEPTED SOLUTIONS

Sumanth16
Kilo Patron

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

 

  1. Navigate to Scripts - Background
  2. 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);
    }

  3. Click 'Run script'

 

 

 

Plz mark my solution as Accept, If you find it helpful.

 

 

Thanks & Regards,

Sumanth meda

View solution in original post

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

View solution in original post

2 REPLIES 2

Sumanth16
Kilo Patron

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

 

  1. Navigate to Scripts - Background
  2. 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);
    }

  3. Click 'Run script'

 

 

 

Plz mark my solution as Accept, If you find it helpful.

 

 

Thanks & Regards,

Sumanth meda

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn