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

Thank you Ankush,

That's exactly what I was looking for. Right on dot. Excellent.

Thanks,

Rajan

 

@Ankush Agrawal 

Could you please look into below post , Thanks in advance. 
ATF Custom Step Query - ServiceNow Community