- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 09:33 AM
Hi, I had a question regarding ATF.
I have a catalog task with a variable in variable set named 'Next Step'. I need to update the variable in order to close the task, but I'm not sure as to how exactly to update the record.
The variable doesn't come from the RITM, therefore I cannot simply use 'Set Variable Value' step as the variable won't show. I thought of using 'run server side script' but the script doesn't update the variable on sc_task. Below script:
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var STEP_15_SYS_ID= 'd9f8dd67db805410bea7550a48961930'; // step sys_id
var step_16_output = steps(STEP_15_SYS_ID);
var grtask = new GlideRecord('sc_task');
grtask.addQuery('request_item',step_16_output.first_record);
grtask.query();
if(grtask.next()){
gs.log("Found task : " + grtask.number);
gs.print(grtask.request_item.variables.next_step);
grtask.request_item.variables.next_step='Solution Approved, Build Required';
grtask.update();
outputs.table = 'sc_task';
outputs.record_id = grtask.sys_id;
}
})(outputs, steps, stepResult, assertEqual);
Now, I'm not sure how to go about the problem. Is this possible through ATF?
Solved! Go to Solution.
- Labels:
-
Automated Test Framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 10:01 AM
Hi,
So I assume Step 15 is record query and it checks RITM record; so update code as below in Run Server Script step
you need to return the step result whether success or failure and return statement
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var STEP_15_SYS_ID= 'd9f8dd67db805410bea7550a48961930'; // step sys_id
var step_16_output = steps(STEP_15_SYS_ID).first_record;
var message = '' + step_16_output;
var grtask = new GlideRecord('sc_task');
grtask.addQuery('request_item',step_16_output);
grtask.query();
if(grtask.next()){
gs.info("Found task : " + grtask.number);
gs.info(grtask.request_item.variables.next_step);
grtask.request_item.variables.next_step='Solution Approved, Build Required';
grtask.update();
outputs.table = 'sc_task';
outputs.record_id = grtask.sys_id;
message = message + 'Found Task ' + grtask.number;
stepResult.setOutputMessage(message);
stepResult.setSuccess();
return true;
}
})(outputs, steps, stepResult, assertEqual);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 04:31 AM
Hi,
Can you try running script in background for some hard-coded catalog task sys_id and RITM
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 05:04 AM
Hi Ankur,
Thanks for your help, I did hit and trial on the background script and was able to understand that the variable on catalog task wasn't coming from the RITM, therefore the line
grtask.request_item.variables.next_step='Solution Approved, Build Required';
Doesn't work.
I just needed to change the line into the below code and it worked:
grtask.variables.next_step='Solution Approved, Build Required';
But thank you so much for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2020 05:08 AM
Hi,
nice catch; even I forgot the same; silly mistake from my side as well
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 05:30 AM
We have an existing article that might help you, in case you are not aware. You can find it here!KB0837191
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 03:35 AM
Hi ANKUR,
How can we Add Multi row variable set which are on catalog task in ATF in order to closed that task ?
Kindly help if any solution exist on it.
Thanks and regards,
Vaishnav Bhagde