how to glide two tables in a function

Servicenow lear
Tera Contributor

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;
                
            }
        
            
  },
        

6 REPLIES 6

Arav
Tera Guru
Tera Guru

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

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 .

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

Mohith Devatte
Tera Sage
Tera Sage

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