How to force a workflow Timer activity to complete and move on for testing?

Community Alums
Not applicable

It used to be the sys_trigger.list and look for WFTimer+sysid of the activity. But not sure what has happened or it is new in london, I cannot find the record WFTimer+my sysid in sys_trigger.list

Does anyone know if something changed with this?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

solution is here.

 

https://community.servicenow.com/community?id=community_question&sys_id=9eb0dc83dbaeaf00f21f5583ca961921&view_source=searchResult

 

 

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Please see solution below to force workflow timer to complete

 

https://community.servicenow.com/community?id=community_question&sys_id=894bfa8ddbd9d3082d1efb651f961944

 

Regards,

Sachin

Community Alums
Not applicable

I tried the script on this page slightly modified for us.

 

forceTimerComplete();


function forceTimerComplete() {
	//how much time do you want to add to the timer from now.   Expiration will be right now + newSeconds.
	var newSeconds = 30;

	var ID = current.sys_id;
	//get the workflow context id for the current request item.
	//i'm using this for a very specific timer, so i only want 1 result.   if you want more, change the if to a while
	var context = new GlideRecord("wf_context");
	context.addQuery("id", ID);
	context.query();
	if(context.next()){
gs.log("Timer 1");
		// find the specific executing activity from the context above.
		var time = new GlideRecord("wf_executing");
		time.addQuery('context', context.sys_id);
		time.addQuery('state', 'waiting');
		time.query();
		if(time.next()){
gs.log("Timer 2");
			//set the name for the workflow timer
			var WFTimer = "WFTimer" + time.sys_id;

			//search the sys_trigger table for the current timer
			var schedule = new GlideRecord("sys_trigger");
			schedule.addQuery("name", WFTimer);
			schedule.query();
			if(schedule.next()){
				gs.log("Timer 3");
				var curTime = schedule.next_action.getDisplayValue();

				var gdt = new GlideDateTime();
				gdt.addSeconds(newSeconds);
				schedule.next_action = gdt;

				var schedDisp = schedule.next_action.getDisplayValue();
				schedule.update();

				gs.addInfoMessage("<br><br><br><br><center><font size = 5>You have chosen to end the timer NOW<br>Timer will now expire at: </font><font size= 5 color='ff0000'>" + schedDisp + "</font><font size=5><br><br> which is " + newSeconds + " seconds from now.</font></center><br><br><br><br>");

				current.work_notes = "Time has been expired early.\nTimer will now be expired at: '" + schedDisp + "'   instead of '" + curTime + "'.";
				current.update();
			}
		}
	}
	action.setRedirectURL(current);
}

 

The 3rd log statement is not executing because the record is not in the sys_trigger table. This is what I faced in my first try.

I guess something has changed now..

 

Community Alums
Not applicable

solution is here.

 

https://community.servicenow.com/community?id=community_question&sys_id=9eb0dc83dbaeaf00f21f5583ca961921&view_source=searchResult

 

 

Community Alums
Not applicable

Needed to make some minor updates to get it to work with latest release.

 

Steps:

1) Create a new UI Action on the 'sc_req_item" table.

2) Name: Force Timer Complete

3) condition (optional if you want to restrict to admin only): gs.hasRole('admin')

 

Script:

forceTimerComplete();


function forceTimerComplete() {

    //how much time do you want to add to the timer from now.   Expiration will be right now + newSeconds.
    var newSeconds = 30;

    var ID = current.sys_id;
    //get the workflow context id for the current request item.
    //using this for a very specific timer, so only 1 result. If you want more, change the if to a while
    var context = new GlideRecord("wf_context");
    context.addQuery("id", ID);
    context.query();
    if (context.next()) {
        gs.log("Timer 1");
        // find the specific executing activity from the context above.
        var time = new GlideRecord("wf_executing");
        time.addQuery('context', context.sys_id);
        time.addQuery('state', 'waiting');
        time.query();
        if (time.next()) {
            gs.log("Timer 2");
            //set the name for the workflow timer
            var WFTimer = "Workflow" + time.context.sys_id;

            //search the sys_trigger table for the current timer
            var schedule = new GlideRecord("sys_trigger");
            schedule.addQuery("name", WFTimer);
            schedule.query();
            if (schedule.next()) {
                gs.log("Timer 3");
                var curTime = schedule.next_action.getDisplayValue();

                var gdt = new GlideDateTime();
                gdt.addSeconds(newSeconds);
                schedule.next_action = gdt;

                var schedDisp = schedule.next_action.getDisplayValue();
                schedule.update();

                gs.addInfoMessage("<br><br><br><br><center><font size = 5>You have chosen to end the timer NOW<br>Timer will now expire at: </font><font size= 5 color='ff0000'>" + schedDisp + "</font><font size=5><br><br> which is " + newSeconds + " seconds from now.</font></center><br><br><br><br>");

                current.work_notes = "Time has been expired early.\nTimer will now be expired at: '" + schedDisp + "'   instead of '" + curTime + "'.";
                current.update();
            }
        }
    }
    action.setRedirectURL(current);
}