- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 08:47 AM
Hi Everyone
I am new to ServiceNow and trying to do the following stuff. I am not getting a lead to do it as I have been using traditional programming IDEs to solve different tasks but did not use an app like ServiceNow earlier. I am trying to do the following:
- make an outbound Rest call to an external RestAPI and get JSON back. (able to do this but the results can not be processed as using Outbound rest messages)
- find a way to process the JSON response with javascript in the test app.
- make authentication with API token with the RestAPI call
Is there any way I could achieve such functionality? Thanks a lot
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 04:10 PM
Check the "Advanced" checkbox.
The body of the script can be generated using REST Message.
- From the Navigator, go to "System Web Services" > " Outbound" > "REST Message".
- Create a new REST Message by clicking on the "New" button.
- Fill in the Endpoint (i.e. enter the URI of the external url. e.g. http://xxx.aaa.com:8080)
- Select "Authenentication type" from pull down
- If there is a HTTP Request header, select the "HTTP Request" tab and insert the required headers.
- Select the "New" button next to the HTTP Methods
- Enter the "Name" and the "HTTP method".
- To test the uri and if there is argument to be passed in the uri, click on the "New" button next to the "Variable Substitution". For example, to replace "id" with some value such as "abc"
- Click the "Test" link under "Related Links" to test the endpoint.
- If all goes well, click on the "Preview Script Usage" link under the "Related Links". This will generate JavaScript code template.
- Paste the generated source code to business rule.
- If using MID Server, edit the source code as needed.
To parse JSON response,
var responseBody = response.getBody();
var response= JSON.parse(responseBody);
for(i=0;i<response.length;i++) {
// process json object
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 09:08 AM
Hi Jamshaid,
You can use the below script in business rule to trigger the integration and get the response.
//call the rest message and method
var r = new sn_ws.RESTMessageV2('rest message name', 'post');
//provide the endpoint
r.setEndpoint('end point');
//json is available on output payload field
r.setRequestBody(current.output_payload + '');
var response = r.execute();
// to get the response body
var responseBody = response.getBody();
//setting response on input payload field
current.input_payload = responseBody;
current.update();
Hope it helps!!
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 09:12 AM
hi there. could you please guide me about it a bit? I am totally new to ServiceNow. Is there any tutorial for it about where to place this code or you could guide by referring to an example? Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 09:28 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 04:10 PM
Check the "Advanced" checkbox.
The body of the script can be generated using REST Message.
- From the Navigator, go to "System Web Services" > " Outbound" > "REST Message".
- Create a new REST Message by clicking on the "New" button.
- Fill in the Endpoint (i.e. enter the URI of the external url. e.g. http://xxx.aaa.com:8080)
- Select "Authenentication type" from pull down
- If there is a HTTP Request header, select the "HTTP Request" tab and insert the required headers.
- Select the "New" button next to the HTTP Methods
- Enter the "Name" and the "HTTP method".
- To test the uri and if there is argument to be passed in the uri, click on the "New" button next to the "Variable Substitution". For example, to replace "id" with some value such as "abc"
- Click the "Test" link under "Related Links" to test the endpoint.
- If all goes well, click on the "Preview Script Usage" link under the "Related Links". This will generate JavaScript code template.
- Paste the generated source code to business rule.
- If using MID Server, edit the source code as needed.
To parse JSON response,
var responseBody = response.getBody();
var response= JSON.parse(responseBody);
for(i=0;i<response.length;i++) {
// process json object
}