Importing data Through Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2025 11:53 PM
We have created Scheduled job to import data from third party into ServiceNow , but we are only receiving 10k records , I have used pagination then also same thing is receiving, can anyone help me to understand if any issues there with my code.
Sample code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 02:18 AM
so what's your concern?
1) API is bringing always same 10k records?
OR
2) API is bringing 10k records in each call but import set is only loading and transforming the 1st 10k records which were fetched?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 02:22 AM
Hello @Ankur Bawiskar , yeah my query is API always bringing the 1st 10k records but the API has more than 30k response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 02:56 AM
try this and see what came in logs
var pagesize = 10000;
var pagestofetch = 10;
var pageoffset = 0;
var j = 0;
var allResults = [];
while (j < pagestofetch) {
gs.log('Fetching page ' + (j + 1));
try {
var r = new sn_ws.RESTMessageV2('testing', 'testing234');
r.setStringParameterNoEscape('sysparm_offset', pageoffset);
r.setStringParameterNoEscape('sysparm_limit', pagesize);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
gs.info("Endpoint: " + r.getEndpoint());
gs.info("Request Body: " + r.getRequestBody());
gs.info("Response Body: " + responseBody);
gs.info("HTTP Status: " + httpStatus);
if (parsed.length === 0) {
gs.log('No more records to fetch.');
break;
}
allResults.push(parsed);
gs.log('Fetched ' + parsed.length + ' records.');
pageoffset += pagesize;
j++;
} catch (ex) {
var message = ex.getMessage();
gs.error('Error fetching records: ' + message);
break;
}
}
gs.log('Total records fetched: ' + allResults.length);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader