Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to query twice the same gliderecord?

rexter1
Tera Expert

Hi guys, I have  script: 

var gr = new GlideAggregate('incident');
    gr.addEncodedQuery("active=true");
    gr.addAggregate('COUNT');
    gr.query();
    var result = 0;
    if (gr.next())
        result = gr.getAggregate('COUNT');
        gs.print("Total number of Active Incidents: " + result);
    

var gr2 = new GlideAggregate('incident');
    gr2.addEncodedQuery("active=true^contact_type=phone");
    gr2.addAggregate('COUNT');
    gr2.query();
    var result2 = 0;
    if (gr2.next())
        result2 = gr2.getAggregate('COUNT');
        gs.print("Total number of Active Incidents with Phone contact: " + result2);

As you can see only the addEncodedQuery changes. Is there any way to "merge" this two script somehow to one, and just have 1 GlideAggregate call? 

Thanks a lot!

1 ACCEPTED SOLUTION

Pranav Bhagat
Kilo Sage

Hi @laszlob 

As they are 2 separate queries so you can't merge those things up.

You can use database views to merget 2 tables together and gliderecord on it .

Check this link

https://codecreative.io/blog/3-strategies-to-fix-nested-gliderecords/

 

Regards

Pranav

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do you want count of active=true and contact_type=phone then you need to use 2nd query

Both the queries are different

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Pranav Bhagat
Kilo Sage

Hi @laszlob 

As they are 2 separate queries so you can't merge those things up.

You can use database views to merget 2 tables together and gliderecord on it .

Check this link

https://codecreative.io/blog/3-strategies-to-fix-nested-gliderecords/

 

Regards

Pranav