how to glide two tables in a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 06:48 PM
Hello all,
I am working on a requirement wherein I am gliding two tables in a function, wanted to know how to go about it.
This is the code I have written for a script include :
copyServiceMappingEntries: function() {
// Get existing associations
var grServices = this._getAllAssociations();
},
_getAllAssociations: function() {
var gr = new GlideRecord("svc_ci_assoc");
gr.query();
return gr;
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;
}
},
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 06:59 PM
Hi,
What is the business requirement here ?
a. In line 3 of function "_getAllAssociations", you are returning the glide record object before "if". So it will never go past that line
b. Also, if you want to check if there is at least 1 record in table "svc_ci_assoc", I suggest you use "if(gr.hasNext())"
Thanks,
Arav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 07:03 AM
The requirement it that it glides the assoc table and see if there is a CI in it if the CI is not there then use the cmdb rel ci table .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 12:50 PM
Ok, please check the suggestions I had provided above.
Once done, you may want to form and return an array of strings that holds the sys ids of business services.
If you run into a specific error or issue after that, please call that out.
Thanks,
Arav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 06:59 PM
Hello , I think based on your code I can understand that if there is a record in svc table then return six glide record object else return code rel code object in that case you need to remove the return statement after gr.query and add few queries also to filter of unwanted records