In ServiceNow Background Script without using addEndcodedQuery how to apply multiple filters

SreenadhChenna
Tera Contributor

Hi,

In ServiceNow Background Script without using addEndcodedQuery() how to apply multiple filters.

If i want to run a Background script in the incident table i want to fetch last 15days incidents which has created and Active=true but i don't want to use addEncodedAQuery()

Thanks,

 

 

1 ACCEPTED SOLUTION

Siva Jyothi M
Mega Sage

Hi @SreenadhChenna,

 

 

 

 

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.addQuery("sys_created_on",'<',gs.daysAgo(15));
gr.query();
while(gr.next()){
    gs.print(gr.number);
}
//gs.print(gr.getRowCount());

 

 

 

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.

 

View solution in original post

3 REPLIES 3

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hi @SreenadhChenna 

Try gr.addQuery('sys_created_on','<',gs.daysAgo(15));

please mark the answer as correct and helpful if helped!

Kind Regards,

Ravi Chandra 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@SreenadhChenna 

then you need to run the query and inside while loop check the comparison i.e. get difference of current time and sys_created_on and if it's 15 then do your logic.

It's always recommended to use encodedQuery wherever possible to reduce the number of records at the first level itself

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Siva Jyothi M
Mega Sage

Hi @SreenadhChenna,

 

 

 

 

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.addQuery("sys_created_on",'<',gs.daysAgo(15));
gr.query();
while(gr.next()){
    gs.print(gr.number);
}
//gs.print(gr.getRowCount());

 

 

 

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.