How to use a variable from one server side script into another server side script in ATF?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2020 06:45 AM
Hi all,
I'm trying to create a record in the step called: Run Server Side Script in ATF (London).
My script is as following:
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var gr = new GlideRecord('sc_req_item');
gr.newRecord();
gr.short_description = 'test123';
var requestSysiD = gr.insert();
outputs.record_id = requestSysiD;
stepResult.setOutputMessage('Service Request Created SysID: ' +requestSysiD);
})(outputs, steps, stepResult, assertEqual);
Into the next ATF step I'd like to also Run Server Side script and use this variable called: requestSysiD
How can I do it?
How can I access the property record_id added to to outputs from another server script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 03:49 AM
Hi! You can access the output from within another server-side script using this syntax:
var requestID = steps(SYS_ID_OF_THE_PREVIOUS_STEP).request_id;
As you can see, unfortunately you've got to hard-code the ID of the step record. I like to keep those as system properties for simpler maintenance and visibility.
Please mark this response as correct/helpful if this is what you've been looking for!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 04:30 AM
Hi,
Check this:
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 05:01 PM
Hi,
I know this is old, but I've come up with a solution for the problem of passing values in and out of the OOTB Run Server Side Script.
Go to the Step Config for Run Server Side Script.
Create in input variable of the type you want.
For example for a record_id, create a variable of type Document Id.
In your script, you can reference the variable through
step.inputs.(variable)
example step.inputs.u_record_id
Here is an example of a test script that uses an input variable Record Id (u_record_id)
(function(outputs, steps, params, stepResult, assertEqual) {
// add test script here
gs.log("steps " + typeof steps);
gs.log("params " + typeof params);
gs.log("step " + typeof step);
gs.log("step.inputs " + typeof step.inputs);
gs.log("step.inputs.u_record_id " + step.inputs.u_record_id);
outputs.record_id = step.inputs.u_record_id + "";
return true;
})(outputs, steps, params, stepResult, assertEqual);
Hope this helps. Mark helpful if it's helpful.
Thanks,
Cody