- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2020 11:44 AM
I am building some ATF Tests to test out various workflows that we have. Some of them have Timers in them (i.e. wait 5 minutes, wait 10 days before expiration). How can I write ATF tests for those workflows which have timers in them that cause "a pause" in time, waiting for time to pass before proceeding to the next step? Is there some command we can add to the ATF testing to tell it that a certain amount of time has passed? Or will it just ignore timers and go to the next step in the workflow?
Thanks
Solved! Go to Solution.
- Labels:
-
Automated Test Framework

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 02:24 PM
Basically, I haven't built out the Description script, I was more interested in having the execution do what I was looking to do.
Here is a screen capture of the part of the test that will move the change request forward...update the timer...
The script that I wrote inside of the Test "Update Change Request Scheduled Job..." to execute the timer activity on the workflow is the following, and it only needs the sys_id of the change request form as the input to query its way thru tables to get to the correct sys_trigger table. There are no outputs. The step just updates the timer for 2 minutes past the time it gets when the step runs and then the step sleeps for 2 minutes to allow the trigger job to actually run.
(function executeStep(inputs, outputs, stepResult, timeout) {
var cntxID = '';
var wfVerID = '';
var actvID = '';
var execID = '';
var nextAction = 'No';
//----Get Current Date Time
var gdt = new GlideDateTime();
var schdt = new GlideDateTime();
gdt.addSeconds(-10680); //Convert Time to Central + 2 minutes
//---------------------------------
var wfcontext = new GlideRecord('wf_context');
wfcontext.addQuery('id', inputs.u_request);
wfcontext.query();
if (wfcontext.next()) {
cntxID = wfcontext.sys_id;
wfVerID = wfcontext.workflow_version;
}
var wfactivity = new GlideRecord('wf_activity');
wfactivity.addQuery('name', 'Wait for CR Planned Start Date');
wfactivity.addQuery('workflow_version.sys_id', wfVerID);
wfactivity.query();
if (wfactivity.next()) {
actvID = wfactivity.sys_id;
}
if (cntxID != '') {
var wfexec = new GlideRecord('wf_executing');
wfexec.addQuery('context.sys_id', cntxID);
wfexec.addQuery('activity', actvID);
wfexec.query();
if (wfexec.next()) {
execID = wfexec.sys_id;
}
}
if (execID != '') {
var sched = new GlideRecord('sys_trigger');
sched.addQuery('document_key', execID);
sched.query();
if (sched.next()) {
schdt = sched.next_action;
sched.next_action = gdt;
nextAction = 'Yes';
sched.update();
}
}
gs.sleep('120000'); //2 Minutes
if (nextAction == 'Yes') {
stepResult.setSuccess();
stepResult.setOutputMessage = "Original Planned Start of " + schdt + " changed to " + gdt;
} else {
stepResult.setFailed();
}
}(inputs, outputs, stepResult, timeout));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 08:05 AM
Thank you for the reply.
So, I am assuming that all this code goes in a custom "Step Configuration". I have never done one of those before, so I am trying to work through it. I copied all your code in it, but I am unsure how you set up an Input Field for the sys_id that we are supposed to be feeding it. How would I do that?
I am assuming since I am doing this from a RITM, I would just send it the sys_id of the RITM.
I am also assuming if I wanted to make it more dynamic, I could make the "time to add" an Input Variable, as well as the name of the wf_activity I am looking for (so as not to have to hard-code those in the code).
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 08:48 AM
You would create the Input field by clicking the New button in the Inputs Related List that displays after you save the code in the Step Configuration.
It would be similar to creating a dictionary field (as far as type, which would be "Reference" and it would be to the "Task" table).
When you use the step that you just built in your test, the field that displays when you configure the step is where you will select the value or if you have a prior step that submits a form, you could use the data pill to get the output value from it.
Yes you can make the time to add dynamic. I did a similar thing with a different step that I built to add a dynamic number of days to the current date so the step could be used for different scenarios where the input was the number of days and the output was a datetime field that returned the added to date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 10:15 AM
Thank you.
I just encountered a very odd issue trying to set up the Input Variable. I choose the "Reference" type, but it never pops up the "Type Specifications" tab to allow me to select the Reference. I thought maybe if I "saved" the record, that would trigger it, but it did not. Instead it gave me an error message:
Doing some research, it looks like other people have had issues too (https://community.servicenow.com/community?id=community_question&sys_id=5eb081d8dbcb33c45ed4a851ca96...). I'll have to see if I can work through that post, and see if there is anything there that will get it working for me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 10:29 AM
Hi jmisky,
Yes, in my PDI, it works fine, but where I built that initially, I had the same issue. The ways I got around it was to build the field as a String and then in the list of the input variables, I added the Reference field to the list so that I could add the table of the reference before changing the type to be type of Reference. All was good then. Hope this helps. I am not sure what occurred in the instance where this happens, but I do know that the instance is much older and has been around a long while, so that may be the common denominator.
Thanks,
Trena
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 12:11 PM
Trena,
Thanks. That is a clever workaround, and allowed me to get it entered.
When I tried it out, it failed on that step. I am not quite sure why, but I have two questions that may lead to the route cause of the problem.
The first one is, you had mentioned using the Task Sys_ID for the input, but I am not working with a Task here, but a RITM. So I think I want to use the Sys_ID for the RITM. Would you agree? Other than my input variable, would I need to change anything else in the code to reflect that? Do I need to change this line (is "input.u_request" supposed to be the name of my input variable?
wfcontext.addQuery('id', inputs.u_request);
The second one is the following line here:
gdt.addSeconds(-10680); //Convert Time to Central + 2 minutes
I am not sure how I should adjust that. I am in the Eastern Time Zone. How did you arrive at -10680?
Thanks for sticking with me and helping me through this. I greatly appreciate it!