- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 01:19 PM
Hello,
I'm wondering if someone can tell me how to see when the last time was that a workflow was used? I keep seeing references to the wf_context table, which shows me some workflows and the last time they were triggered, but that still requires a lot of manual effort to look at dates and compare workflows in that table to the amount of workflows in our system. Ideally, I'd like to have a report that shows workflows not used in the last 6 months so we can review them and see if they can be set to inactive. Has anyone created something like that before?
Solved! Go to Solution.
- Labels:
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 02:36 PM
Sure it would be easy enough to modify the script I previously provided to check for name instead of sys_id, see updated script below. Also -- if any of my answers in this thread have been helpful or solved your question, I would really appreciate it if you mark them as Helpful and/or Correct!
checkWorkflows();
function checkWorkflows() {
var publishedWfGr = new GlideRecord('wf_workflow_version');
publishedWfGr.addEncodedQuery('published=true');
publishedWfGr.query();
var staleWfList = [];
while (publishedWfGr.next()) {
var wfContextGr = new GlideRecord('wf_context');
wfContextGr.addEncodedQuery(gs.getMessage('workflow_version.name={0}^sys_created_onONLast 6 months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()', publishedWfGr.getValue('name')));
wfContextGr.setLimit(1);
wfContextGr.orderByDesc('sys_created_on');
wfContextGr.query();
if (!wfContextGr.next()) {
staleWfList.push('Published workflow has not been triggered in past 6 months: ' + publishedWfGr.getDisplayValue());
}
}
var resultSummary = staleWfList.join('\n');
if (resultSummary) {
gs.info(resultSummary);
//could you gs.eventQueue() here instead to trigger scheduled email, include resultSummary as event.parm1 or event.parm2
}
}
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2022 04:14 PM
Hi Casey,
It's possible that the workflow contexts you have displayed in the attached screenshots are related to workflow versions which are different than the currently published workflow version, because your filter is on Workflow.Name contains xyz, whereas you should be entering the sys_id of the workflow version record to perform the lookup for Workflow is xyz on the workflow context table.
Hopefully that makes sense.
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 10:31 AM
That makes sense, and if I look at those workflow contexts, you are right in that the workflows have been updated (meaning a different sys_id) compared to the currently published workflow.
Would there be a way to do this by the name of the workflow? I can see versions being different quite often since some workflows are updated regularly. But the name of the workflow should essentially never change unless there was a mistake in it (which would likely be caught during development anyway). But I think that scenario is way less likely than the version changing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 02:36 PM
Sure it would be easy enough to modify the script I previously provided to check for name instead of sys_id, see updated script below. Also -- if any of my answers in this thread have been helpful or solved your question, I would really appreciate it if you mark them as Helpful and/or Correct!
checkWorkflows();
function checkWorkflows() {
var publishedWfGr = new GlideRecord('wf_workflow_version');
publishedWfGr.addEncodedQuery('published=true');
publishedWfGr.query();
var staleWfList = [];
while (publishedWfGr.next()) {
var wfContextGr = new GlideRecord('wf_context');
wfContextGr.addEncodedQuery(gs.getMessage('workflow_version.name={0}^sys_created_onONLast 6 months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()', publishedWfGr.getValue('name')));
wfContextGr.setLimit(1);
wfContextGr.orderByDesc('sys_created_on');
wfContextGr.query();
if (!wfContextGr.next()) {
staleWfList.push('Published workflow has not been triggered in past 6 months: ' + publishedWfGr.getDisplayValue());
}
}
var resultSummary = staleWfList.join('\n');
if (resultSummary) {
gs.info(resultSummary);
//could you gs.eventQueue() here instead to trigger scheduled email, include resultSummary as event.parm1 or event.parm2
}
}
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2022 09:39 AM
That did the trick! Thank you so much!