Glide Query based on multiple values

ramandeepgarg6
Tera Expert

Hi Team,

I have a Domains table which contains all domains. I have another table SubDomains which contains subset of domains. I want to query Domains table based on Subdomains table. Please telll how to do that. Will below code work?

var subDomains = new GlideRecord('u_subDomains');

var arraysubdomains = [];

subdomains.query();

while (subdomains.next()){

arraysubdomains.push(subdomains.name);

}

var domains = new GlideRecord('u_domains');

domains.addQuery('name' 'IN' arraysubdomains.toString());

domains.addQuery('active', 'true');

domains.query();

Regards

Ramandeep

4 REPLIES 4

Sebastian R_
Kilo Sage

I corrected a few things, but I think to provide us a short example.


You query u_subDomains and then query u_domains with the same name. Does this make sense?



var subDomains = new GlideRecord('u_subDomains');


var arraysubdomains = [];


subdomains.query();


while (subdomains.next()){


arraysubdomains.push(subdomains.name);


}



var domains = new GlideRecord('u_domains');


domains.addQuery('name', 'IN', arraysubdomains.join(','));


domains.addQuery('active', 'true');


domains.query();


Hi Sebastian,



Thank you for looking into this. Please see requirement as below:



"Domains" table contain all the domains and its details. Few domains are active and few are inactive. Domains Active status changes quite frequently. It does not contain any cost related information.



"Subdomains" table contains the name of the domains and cost associated to them. Only those domains are displayed which have any cost associated to them. It can happen that this table contains few domains which have some old cost related to them but these are currently inactive in Domains table.



Now requirement is to display "All Active domains from 'Domains' table" + "All Domains from 'Subdomains' table. So the purpose is to display all the active domains from Domains table and we also need to display those inactive domains which are present in subdomains table



Regards


Ramandeep


mohamadcharafed
ServiceNow Employee
ServiceNow Employee

Hi Ramandeep,


The script will work but if you have a huge amount of records in there in the future this may cause problems.


Consider creating a Database View on the tables instead if you need to do this query often :



http://wiki.servicenow.com/index.php?title=Database_Views#gsc.tab=0



Cheers


Mohamad


Hi Mohamad,



Thank you for looking into this. Please see requirement as below:



"Domains" table contain all the domains and its details. Few domains are active and few are inactive. Domains Active status changes quite frequently. It does not contain any cost related information.



"Subdomains" table contains the name of the domains and cost associated to them. Only those domains are displayed which have any cost associated to them. It can happen that this table contains few domains which have some old cost related to them but these are currently inactive in Domains table.



Now requirement is to display "All Active domains from 'Domains' table" + "All Domains from 'Subdomains' table. So the purpose is to display all the active domains from Domains table and we also need to display those inactive domains which are present in subdomains table



Regards


Ramandeep