From 28bff3757f6d7b7485660f7f23cbc9de70c7c972 Mon Sep 17 00:00:00 2001 From: ChandBasha-code Date: Sun, 12 Oct 2025 16:40:16 +0530 Subject: [PATCH 1/2] DataloaderFromIntuneAPI_README.md --- .../DataloaderFromIntuneAPI_README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataloaderFromIntuneAPI_README.md 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. From 9099296d0c2dd269bb6d0bf82b150f05e39172ea Mon Sep 17 00:00:00 2001 From: ChandBasha-code Date: Sun, 12 Oct 2025 16:40:56 +0530 Subject: [PATCH 2/2] Create DataLoaderFromIntuneAPI.js --- .../DataLoaderFromIntuneAPI.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST/DataLoaderFromIntuneAPI.js 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);