Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Outputs variable of ATF Serverside script

Nitesh Balusu
Giga Guru

Hello Developers,

 

I need to output the result of a serverside script that i have written to use in the next step of ATF. the result of the script is a string which looks something like this "/api/now/table/incident/e1ce0900dbc123c075dd9837db961968". Please take a look at script and let me know how the variable "jsonresult_response" needs to be passed to the next step.

Thanks.

 

(function(outputs, steps, stepResult, assertEqual) {

	var jsonresult_response;
	var record_id;

	var res= new GlideRecord("sys_atf_test_result_item");
	res.addQuery('step','2f927cc8db41e3c4af4df35aaf96191c');
	res.orderByDesc("sys_updated_on");
	res.setLimit(1);
	res.query();

	while(res.next()) {

		var jsonresult=res.output;
		
		
		var startindex = jsonresult.indexOf("/api/now/table/incident/");
		var endindex = jsonresult.indexOf("Cache-control");
		jsonresult_response=jsonresult.substring(startindex,endindex);
		
		outputs.record_id=jsonresult_response;
		gs.info("output is "+outputs.record_id);
	}
		

		
})(outputs, steps, stepResult, assertEqual);

1 ACCEPTED SOLUTION

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Sree

The max length of record_id is 32 characters as it represents sys_id. You should ideally create a new output variable under the step configuration 'Run Server Side Script'.

If there is a limitation to do this and you are bound to use OOB output variables, you can use the variable 'table' instead of 'record_id'. The max length of 'table' is 80 characters.

 

P.S. Please mark helpful/correct if appropriate to help others identifying the most relevant answer.

--

Best regards

Ankush

View solution in original post

7 REPLIES 7

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Sree

The max length of record_id is 32 characters as it represents sys_id. You should ideally create a new output variable under the step configuration 'Run Server Side Script'.

If there is a limitation to do this and you are bound to use OOB output variables, you can use the variable 'table' instead of 'record_id'. The max length of 'table' is 80 characters.

 

P.S. Please mark helpful/correct if appropriate to help others identifying the most relevant answer.

--

Best regards

Ankush

Got it! Thanks!

hi Ankush,

 

I have similar requirement. Want to pass on out put of first step to next step.

Can you please guide me how do I get this to pass on to next step? What do I need to do in next step?

Please advise. 

Thanks,

Step 1:

(function(outputs, steps, stepResult, assertEqual) {
// add test script here

:

:

:

var response = request.execute();
outputs = response.getBody();
})(outputs, steps, stepResult, assertEqual);

 

 

Step 2:

??? var output_Step1 = steps('xxxxxxxxxxxxxxxxxxxx').outputs ; // Passing sys_id of Step 1

 

I am not getting anything if I do this. Please advise. 

Thanks,

Rajan Mehta

 

 

 

 

 

Hi Rajan

 

There are 2 catches:

  1. outputs is the returned object and the output variables are stored inside it, e.g.: outputs.record_id etc. Hence Step 1 should have the line as
    outputs.record_id = response.getBody();

    Similarly Step 2 should refer this as:
    var output_Step1 = steps('xxxxxxxxxxxxxxxxxxxx').outputs.record_id;

  2. I believe getBody might return a large JSON object. If yes, you can go to the step configuration 'Run Server Side Script' and create a new output variable there of type Name-Value Pair (say, u_json_output). This can store JSON string and set via outputs.u_json_output = response.getBody() and can be referred in subsequent steps as

    var output_Step1 = steps('xxxxxxxxxxxxxxxxxxxx').outputs.u_json_output;

--
Best regards
Ankush

P.S. Please mark helpful to help fellow Community user in identifying useful answers.