Timers - how to force a timer to go through before the end

brandong
Kilo Contributor

Hello everyone,

  I currently have a workflow the leverages 1 day timers which after 1 day, it checks to see if a field is populated, then creates a task if it is. Let's say that field is populated within the first 3 hours of that timer, how can we force the timer to end without having to wait another 21 hours?  Thank you for the help.

1 ACCEPTED SOLUTION

you have to create 1

UI Action

Name: Skip Timer

Table: Requested Item

Client: False

/*
* 1. In order for this script to work, the UI action must be on the Requested Item table.
* 2. on the sys_trigger table, there is a field "Upgrade Safe"   which is a true/false field.   It's "writable" only by the role of "maint"   which is a ServiceNow Employee role.
You need to edit the security of that role and allow whatever role needed to write to that field.

* 3. With this being a restricted field, it's probably not best practice to edit it, and after an upgrade it may be affected where the UI Action doesn't work anymore.
*/


ReclaimAllDevices();


function ReclaimAllDevices() {
	//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()){

		// find the specific executing activity from the context above.
		var time = new GlideRecord("wf_executing");
		time.addQuery('context', context.sys_id);
		time.addQuery('stage', 'loan');
		time.query();
		if(time.next()){

			//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()){
				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);
}

View solution in original post

8 REPLIES 8

Mike Patel
Tera Sage

Do you want to add button to skip timer?

would that be on the back end available to ITIL users and fulfillers only?

Meaning the fulfiller would be able to populate the field, then go to the workflow, navigate to the specific timer that is active, and then click "skip timer?"

fulfiller will populate the field and save the record than go to RITM and click on skip timer button.