Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
getDevices: function(importSetTable) {
var endPoint = null;
var isEndofDevices = false;

while (!isEndofDevices) {
// Call REST Message Method
var url = new sn_ws.RESTMessageV2('Servicenow-Rest', 'GetDevice');

if (endPoint !== null) {
url.setEndpoint(endPoint); // Set the endpoint from REST Message method
}

var response = url.execute(); // Execute endpoint
var responseBody = response.getBody(); // Capture the response body
var httpStatus = response.getStatusCode(); // Capture response status code (200 for success)

// Parse the response to JSON format
var parsedResponse = JSON.parse(responseBody);
var deviceData = parsedResponse.value;

// Loop through each record and insert data into import set table
for (var i = 0; i < deviceData.length; i++) {
importSetTable.insert(deviceData[i]);
}

if (parsedResponse["@odata.nextLink"]) { // Pagination : Check if response has next link
// Copy next data link to endPoint variable
endPoint = parsedResponse["@odata.nextLink"];
} else {
isEndofDevices = true;
}
} // End of while loop
},
Calling from datasource

var data = new Utils().getDevices(import_set_table);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The getDevices() function automates the process of:
Calling a REST Message defined in ServiceNow.
Retrieving device data in JSON format.
Handling pagination using the @odata.nextLink attribute.
Inserting each record into a specified Import Set table for further transformation.
Loading