diff --git a/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataLoaderFromIntuneAPI.js b/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataLoaderFromIntuneAPI.js new file mode 100644 index 0000000000..2938c0e999 --- /dev/null +++ b/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataLoaderFromIntuneAPI.js @@ -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); diff --git a/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataloaderFromIntuneAPI_README.md b/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataloaderFromIntuneAPI_README.md new file mode 100644 index 0000000000..b5d5b8951b --- /dev/null +++ b/Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataloaderFromIntuneAPI_README.md @@ -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.