- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Timer activities are used in ServiceNow workflows for lots of things. Adding a wait period in the workflow, to deal with autoclosure of requests are some of the uses.
But testing the workflows with Timer could be challenging, if you have wait for the said period for the request to move forward. And it can be frustrating experience unless you change the wait period manually.
Well, you neither need to wait for the timer to complete nor need to change the timer value. This below will show you one of the way where you can manually nudge the timer activity forward and also attempts at explaining how these system tables are related.
Internally, all the timer activities from a active workflow context are converted into schedule jobs and names of these jobs start with 'WFTimer'
The workflow activities that are currently being executed for a workflow context are stored wf_executing.
There does not appear to be a direct way for traversing the sys_trigger table (this has the list of scheduled jobs that are pending execution) and find the appropriate timer job.
But luckily we can use nested queries and use the relationships between these tables to get the job corresponding to the timer activity.
You can use a script like below to nudge your timer activity forward.
var getContext = new GlideRecord('wf_executing');
getContext.addEncodedQuery('context.table=sc_req_item^context.id=0a1ec3c110a6760004a5d6b7f3ddbe83^activity=f0e7c1aab92e2200b07e1a8041ef01b6');
getContext.query();
if(getContext.next()) {
var getTimer = new GlideRecord('sys_trigger');
getTimer.addEncodedQuery('name=WFTimer'+getContext.sys_id);
getTimer.query();
if(getTimer.next()) {
getTimer.next_action=gs.nowDateTime(); //Set the current time to nudge it forward
getTimer.update();
}
}
The outer query will get the currently executing workflow context activity related to the timer.You will need to pass the sys_id of the RITM for context.id and sys_id of the activity related to timer.
You will need to pass the timer's sys_id to activity. The timer sys_id can be easily obtained by opening the current workflow version record from wf_workflow_version table. Look into the Workflow Activities related list and copy the sys_id of the timer activity.
The script above will set the execution time with current time. Once the scheduled job is executed, the workflow will resume and will transition forward through as defined.
Note: Nested queries should be avoided since they might cause performance hit. I have used this pattern for simplicity. You can find a good blog here by tltoulson that explains it.
- 2,592 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.