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

hi,

can you be a little more specific .

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 .

how can I go about this code for this requirement ?

this is what i updated :

_getAllAssociations: function() {
        
        var gr = new GlideRecord("svc_ci_assoc");
        gr.addEncodedQuery('service_id.service_classificationINBusiness Service,Application Service,Technical Service')
        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;
                
            }