- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2018 06:05 AM
Business service display page has a link with caption "List CIs". This link when clicked returns related CI list. I want to fetch such list using API or Script. But I couldn't find any public API for the same. I also tried to write script but it returns way more CI's than I am interested in. Is there a away to fetch exact list of CI's returned by "List CIs" link which makes following REST call :
https://devxxxxx.service-now.com/cmdb_ci_list.do?sysparm_query=sys_idINjavascript:saListCis('sys_id')
While "ListCIs" link returns only 11 CIs, my script returns 676 CIs (when break condition is on 100 level).
My scirpt:
var sys_id = g_request.getParameter("systemId");
var record = new GlideRecord('cmdb_rel_ci');
var childList = [];
var i = 0;
childList.push(sys_id);
while(i < childList.length) {
record = new GlideRecord('cmdb_rel_ci');
record.addQuery('parent', childList[i]);
g_processor.writeOutput("text/plain", "\n\nCalling for " + i + "\t value : " + childList[i] + "\t length : " + childList.length);
record.query();
record.getAttribute();
var relId = "";
while (record.next()) {
relId = record.getValue("sys_id");
childList.push(record.child.toString());
}
if(relId == "")
g_processor.writeOutput("text/plain", "\tDetails not found for: " + childList[i]);
i++;
if( i > 100)
break;
}
Do we need to add any other conditions in script or is there any other way to achieve "List Cis" behavior?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2018 12:41 PM
That URL is has the information that you need to build a REST query. "cmdb_ci" is the table name, and "sysparm_query" is an option in REST URIs. In your instance you should navigate to the "REST API Explorer", which provides a GUI to help build a REST URI. It also has code examples for a few different scripting languages such as JavaScript and cURL.
https://developer.servicenow.com/app.do#!/search?category=All&v=london&q=rest%20api%20explorer&page=1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2018 10:42 PM
Thank you Rich.
Following query does work as you mentioned:
curl -H "Accept:application/json" --user "userName:password" "https://devXXXXX.service-now.com/api/now/table/cmdb_ci?sysparm_query=sys_idINjavascript:saListCis('SYSID')" --request GET --header "Accept:appl;2"