Skip to content

Commit 09ffe07

Browse files
authored
Retrieve CIs based on type (ServiceNowDevProgram#876)
* Create RetrieveCis.js Created Scripted Rest Resource for the API to Retrieve CIs * Update CmdbApi.js Added function getCis to retrieves Configuration Items (CIs) based on the specified CI type. * Update readme.md This file contains a ServiceNow script that implements a function for retrieving Configuration Items (CIs) based on a specified CI type.
1 parent ba72b4a commit 09ffe07

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Scripted REST Api/CMDB API/CmdbApi.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,27 @@ createCiRelationship: function() {
299299
sysparm_limit: 100
300300
});
301301
},
302+
303+
/**
304+
* Retrieves Configuration Items (CIs) based on the specified CI type.
305+
* Mapped to GET /cis/{ci_type}
306+
* @returns {GlideRecordStream} A stream of GlideRecord objects representing the CIs.
307+
* @throws {BadRequestError} If an invalid CI type is provided.
308+
*/
309+
getCis: function() {
310+
var self = this;
311+
312+
var ciType = self.getPathParam('ci_type', '');
313+
314+
if (!self._isValidCiType(ciType)) {
315+
return sn_ws_err.BadRequestError('Invalid CI Type provided:' + ciType);
316+
}
317+
318+
return self._getGrResultStream(ciType, null, {
319+
sysparm_limit: 100
320+
});
321+
322+
},
302323

303324
/**
304325
* Determine the type of source ID.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
2+
3+
// implement resource here
4+
return new CmdbApi(request, response).getCis();
5+
6+
})(request, response);

Scripted REST Api/CMDB API/readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Table of Contents
88
4. Delete CI Relationship
99
5. Retrieve CI Group
1010
6. Retrieve CI Relationship types
11+
7. Retrieve CIs
1112

1213
1. Create CIs
1314
This API is designed to create Configuration Items (CIs).
@@ -99,3 +100,17 @@ Table of Contents
99100
Response:
100101
Status Code: 200 OK
101102
Response Body: Details of CI Relationship types
103+
104+
7. Retrieve CIs
105+
Scripted REST API Resource contains a ServiceNow script that implements a function for retrieving Configuration Items (CIs) based on a specified CI type.
106+
Request Details:
107+
Type: HTTP
108+
Method: GET
109+
URI: https://<service-now-___domain>.service-now.com/api/cis/{ci_type}
110+
Headers:
111+
Accept: application/json
112+
Content-Type: application/json
113+
Request Body: NA
114+
Response:
115+
Status Code: 200 OK
116+
Response Body: JSON Details of CIs based on the given type

0 commit comments

Comments
 (0)