Schedule job to call a rest Message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 06:27 AM
Hi
I have built an integration with a third pary tool. I am able to send and retrieve the information from the tool.
I am building a scheduled job to retrive the tickets from the tird party tool.
Can anyone help me in finding out the no of records that are retrieved by the scheduled job and how to parse the data that is retrived an update the Request item table.
This is the code that is used to retrive the ticket information.
try {
var r = new sn_ws.RESTMessageV2('XXXXXX', 'Select');
r.setStringParameterNoEscape('ritm_number', 'RITM0190158');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
Appreciate the help
Vijay
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 06:40 AM
Hi Vijay,
So you must be getting some response; print that; most probably it would be json object and you need to parse that json and then update RITM table
try {
var r = new sn_ws.RESTMessageV2('XXXXXX', 'Select');
r.setStringParameterNoEscape('ritm_number', 'RITM0190158');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info('Response is: ' + responseBody);
}
catch(ex) {
var message = ex.message;
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 06:47 AM
Hi there,
If interested in the number of record, assuming this is against an other ServiceNow instance on sc_req_item, you could go for something like:
var length = JSON.parse(responseBody).result.length;
gs.info(length);
And an example for parsing:
var length = JSON.parse(responseBody).result.length;
for(var i = 0; i < length; i++) {
var short_description = JSON.parse(responseBody).result[i].short_description;
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 07:11 AM
Hi Mark
The issue that i am trying to address is to this. WHen I execute this it would pull only one record. I want to use the scheduled job to pull all the records that are updated on the third party tool.
var r =new sn_ws.RESTMessageV2('XXXXXX', 'Select');
r.setStringParameterNoEscape('ritm_number', 'RITM0190158');
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 07:42 AM
I don't about your 3rd party tool ofcourse, though taking ServiceNow as example, with below you could already obtain all records (added a setLimit:10).
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://some-instance.service-now.com/api/now/table/sc_req_item?sysparm_limit=10');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
gs.log(response.getBody());
It depends on the REST Message, Method, etc.. you are using. This example is a GET on the whole table, with some additional parks (in this case just a setlimit, though active=true, etc would also be possible).
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field