diff --git a/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader - REST API Intune.js b/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader - REST API Intune.js new file mode 100644 index 0000000000..1b19059ffe --- /dev/null +++ b/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader - REST API Intune.js @@ -0,0 +1,37 @@ +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); + diff --git "a/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader \342\200\223 REST API of Intune README.md" "b/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader \342\200\223 REST API of Intune README.md" new file mode 100644 index 0000000000..bd252a746e --- /dev/null +++ "b/Integration/RESTMessageV2/Reusable RESTMessageV2 retry pattern/Device Data Loader \342\200\223 REST API of Intune README.md" @@ -0,0 +1,9 @@ +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.