Skip to content

Commit 6332768

Browse files
Intune Device Data loading into ImportSet Table from API (#2059)
* DataloaderFromIntuneAPI_README.md * Create DataLoaderFromIntuneAPI.js
1 parent 2e7d910 commit 6332768

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
getDevices: function(importSetTable) {
2+
var endPoint = null;
3+
var isEndofDevices = false;
4+
5+
while (!isEndofDevices) {
6+
// Call REST Message Method
7+
var url = new sn_ws.RESTMessageV2('Servicenow-Rest', 'GetDevice');
8+
9+
if (endPoint !== null) {
10+
url.setEndpoint(endPoint); // Set the endpoint from REST Message method
11+
}
12+
13+
var response = url.execute(); // Execute endpoint
14+
var responseBody = response.getBody(); // Capture the response body
15+
var httpStatus = response.getStatusCode(); // Capture response status code (200 for success)
16+
17+
// Parse the response to JSON format
18+
var parsedResponse = JSON.parse(responseBody);
19+
var deviceData = parsedResponse.value;
20+
21+
// Loop through each record and insert data into import set table
22+
for (var i = 0; i < deviceData.length; i++) {
23+
importSetTable.insert(deviceData[i]);
24+
}
25+
26+
if (parsedResponse["@odata.nextLink"]) { // Pagination : Check if response has next link
27+
// Copy next data link to endPoint variable
28+
endPoint = parsedResponse["@odata.nextLink"];
29+
} else {
30+
isEndofDevices = true;
31+
}
32+
} // End of while loop
33+
},
34+
Calling from datasource
35+
36+
var data = new Utils().getDevices(import_set_table);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The getDevices() function automates the process of:
2+
Calling a REST Message defined in ServiceNow.
3+
Retrieving device data in JSON format.
4+
Handling pagination using the @odata.nextLink attribute.
5+
Inserting each record into a specified Import Set table for further transformation.

0 commit comments

Comments
 (0)