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.

Manage REST Message response (getBody())

LdR
Tera Expert

I would need to derive, starting from the body of a response to a REST call {responseBody = response.getBody ();} the amount of rows, and extract single field arrays in order to populate a table.
I saw on the Documentation that the getBody () method returns a string, whose syntax, however, is like a JSON.

How can I solve?
Thank you ☺

1 REPLY 1

Brian Dailey1
Kilo Sage

Hi Leo,

You are correct, I believe it is JSON.  Here is an example of how to use it from some of the OOB code to parse the response back into an object:

 

			var responseBody = response.getBody();
			
			var parser = new JSONParser();
			var parsed = parser.parse(responseBody);

 

This is from the (OOB) GoogleCaptcha script include.  Let us know if you have more questions.

 

Thanks,

-Brian