- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 07:00 PM
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,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 09:44 PM - edited 09-05-2023 09:46 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 07:43 PM
Try gr.addQuery('sys_created_on','<',gs.daysAgo(15));
please mark the answer as correct and helpful if helped!
Kind Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 07:55 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 09:44 PM - edited 09-05-2023 09:46 PM
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.