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.

Scheduled Job script to call JSON Method GET

manji5
Tera Expert

Hi All,

 

I have a REST message of type GET (Location data )

Next Step is to create a Scheduled job to parse this REST message in a Import set table and later transform it to the Location table.

 

Any idea on the script to call the GET method JSON via a scheduled job or any other way to do it.

 

Thank you,

Regards,

Ranjit

1 ACCEPTED SOLUTION

manji5
Tera Expert

Hi Akshay,

 

I finally used the Flow Designer and the REST API action which was simple and straight forward as I didn't need scripting  to generate the Object and parse it via the Flow 

 

Appreciate your help 

 

Thank you,

Regards,

Manji

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hello @manji5 

 

Could you please try below code snippet 

 

               var request, response, status;
		request = new sn_ws.RESTMessageV2();
		request.setEndpoint('https://xyz.com'); 
		request.setHttpMethod('GET');
		request.setRequestHeader("Accept","application/json");
		request.setRequestHeader('Content-Type','application/json');
		response = request.execute();
		gs.info('Response body' + response.getBody());
		var JSONData = new global.JSON().decode(response.getBody());
		gs.info('Country Code: '+ JSONData.countryCode + ' Country Name: '+JSONData.countryName);
		return JSONData.countryCode + ' , ' + JSONData.countryName;

 

Please Mark Correct & 👍 Helpful, if applicable.

 

manji5
Tera Expert

Hi Akshay,

 

I finally used the Flow Designer and the REST API action which was simple and straight forward as I didn't need scripting  to generate the Object and parse it via the Flow 

 

Appreciate your help 

 

Thank you,

Regards,

Manji