- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 08:05 AM
Hi All,
I am still learning JS and new to servicenow.
I have a requirement where in we want to pull data from cmdb_rel_ci table.
: parent should be a SERVICE and type should be Depends on :: Used By.
what query should i use to have it in my code ?
_getAllAssociations: function() {
var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("type", ?);
gr.addQuery("parent", ?)
gr.query();
return gr;
Kindly refer the screenshot for reference wherein Securoty lending is a service and Xbox is a CI using it, like that I want all services and its CI data pulled in.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 08:20 AM
Hi, please try code below to get the data that you are looking for:
var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery('type=1a9cb166f1571100a92eb60da2bce5c5^parent.sys_class_name=cmdb_ci_service');
gr.query();
while (gr.next()) {
// do something
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 11:10 AM
this is what i am doing:
_getAllAssociations: function() {
var gr = new GlideRecord("svc_ci_assoc");
gr.query();
if(gr.next())
{
return gr;
}
else
{
var grRel = new GlideRecord('cmdb_rel_ci');
grRel.addEncodedQuery('type=1a9cb166f1571100a92eb60da2bce5c5^parent.sys_class_name=cmdb_ci_service');
grRel.query();
return grRel;
}
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 08:35 AM
Hey
You can try below code:
var ciList = [];
var relatedCIs = new GlideRecord('cmdb_rel_ci');
relatedCIs.addEncodedQuery('type=cb5592603751200032ff8c00dfbe5d17^parent.nameSTARTSWITHSecurity lending^parent.sys_class_name=cmdb_ci_service^child=46a438a8a9fe19810011dc213ad798a5');// change child's sys_id with xbox one
relatedCIs.query();
while (relatedCIs.next()) {
ciList.push(relatedCIs.getUniqueValue());
}
return ciList.toString();
Aman Kumar