File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Integration/Rest Integration Send Attachment Payload/Send attachment payload via REST Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments