How to cancel a workflow timer

Keri1
Kilo Expert

We have a "consent through silence" approach in our workflows where the system owner has 3 days to approve a RITM before it is auto-approved. The potential issue is what happens if the RITM is manually approved. Later in the workflow we have a Join activity that gets hung up because the timer is still running. While I don't think most requests will get done before the timer ends, we want to be sure it doesn't become an issue in production. I'm not sure what we could put in the workflow or a business rule to cancel this timer; any suggestions?

find_real_file.png

1 ACCEPTED SOLUTION

Keri1
Kilo Expert

My coworker was able to use feedback from another post to come up with a solution. Sharing in case it helps others.

In the workflow we added a Run Script after the approval task that runs if the task is marked approved. The script then checks the ongoing activities based on name and it's activity index # to see if it exists and delete it. For our workflows the index # could vary so there has to be an Or condition to check more than one possibility.

 

var wf = new GlideRecord("wf_context");
wf.addQuery('sys_id', current.context);
wf.query();
while (wf.next())
{
    var wfe = new GlideRecord("wf_executing");
    wfe.addQuery('context', wf.sys_id);
    wfe.addQuery(activity.getDisplayValue(); "Activity Name");
    var qc = wfe.addQuery('activity_index', #);
    qc.addOrCondition('activity_index, #);
    wfe.query();
    while (wfe.next())
    {
        wfe.deleteRecord();
    }
}

View solution in original post

8 REPLIES 8

Keri1
Kilo Expert

My coworker was able to use feedback from another post to come up with a solution. Sharing in case it helps others.

In the workflow we added a Run Script after the approval task that runs if the task is marked approved. The script then checks the ongoing activities based on name and it's activity index # to see if it exists and delete it. For our workflows the index # could vary so there has to be an Or condition to check more than one possibility.

 

var wf = new GlideRecord("wf_context");
wf.addQuery('sys_id', current.context);
wf.query();
while (wf.next())
{
    var wfe = new GlideRecord("wf_executing");
    wfe.addQuery('context', wf.sys_id);
    wfe.addQuery(activity.getDisplayValue(); "Activity Name");
    var qc = wfe.addQuery('activity_index', #);
    qc.addOrCondition('activity_index, #);
    wfe.query();
    while (wfe.next())
    {
        wfe.deleteRecord();
    }
}

ankita1506
Tera Contributor

Hey where di you add the run script. I have a similar condition where a CTask & Timer are parallely created and despite the task being closed, RITM stays open until xtimer is completed.. Can you guide on how to close the RITM immediately after the task is completed. Because of the Timer running, the closed complete node of the CTask is not executing

nancystodd1
Giga Contributor

I know this post is two years old, but I recently had the need to use it to cancel a workflow and I found there were a couple of typos that caused it to not work. I am sharing the version that worked for me here in case someone else wants to use it. I moved the variables that need to be customized to the top to make it easier to see what needs changing.

var actName = "<your_activity name>";
var contextid = "<your_wf_context_sysid>"; //Inside workflow, I used: activity.context
var actIndex1 = "<your_activity_index_1>";
var actIndex2 = "<your_activity_index_2>"; //if needed

var wf = new GlideRecord("wf_context");
wf.addQuery('sys_id', contextid);
wf.query();
while (wf.next())
{
	var wfe = new GlideRecord("wf_executing");
	wfe.addQuery('context', wf.sys_id);
	wfe.addQuery('activity.name', actName);
	var qc = wfe.addQuery('activity_index', actIndex1);
		qc.addOrCondition('activity_index', actIndex2); // Can comment out if not needed
	wfe.query();
	while (wfe.next())
	{
		wfe.deleteRecord();
	}
}

 

Deleting the record seemed (potentially?) problematic, but this script instead will cause the Timer to end based on current datetime.

 

killTimer(); 
function killTimer() {
    var actName = "Timer Activity Name";
    var eQuery = 'context.id=' + current.sys_id + '^activity.name=' + actName;     
var wfe = new GlideRecord("wf_executing");
    wfe.addEncodedQuery(eQuery);
    wfe.query();
    if (wfe.next()) {
        var trig = new GlideRecord("sys_trigger");
        trig.addQuery('document_key', wfe.sys_id);
        trig.query();
        if (trig.next()) {
            var gdt = new GlideDateTime();
            trig.next_action = gdt;
            trig.update();
        }
    }
}