- 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 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 09:22 AM
Thank you this works,
just a quick query on it , since I am trying to glide record 2 tables in a function how can i do that and i think that should fix my issue.
Please, refer the code below :
copyServiceMappingEntries: function() {
// Get existing associations
var grServices = this._getAllAssociations();
// Delete the current copies
this._deleteExistingCopies();
// Add the new copies
this._addAllAssociations(grServices);
},
_getAllAssociations: function() {
var gr = new GlideRecord('cmdb_rel_ci');
gr.addEncodedQuery('type=1a9cb166f1571100a92eb60da2bce5c5^parent.sys_class_name=cmdb_ci_service');
gr.query();
return gr;
var gr = new GlideRecord("svc_ci_assoc");
gr.query();
return gr;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 10:22 AM
I am not sure what your goal is for this code. In general, You can't return twice in a function and you can't reliable return 2 different GlideRecord queries in the same function either. Your best bet would be to create 2 separate functions that query and return what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 10:25 AM
I deal goal is to pull data from two tables, cmdb and assoc table.