scripting query Date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 02:59 AM
Hello Experts,
I am having query above the date field. how to apply the date filter with "at of after" condition.
var gdt = new GlideDate();
var date = gdt.getByFormat("yyyy-MM-dd");
gs.info('Todays Date ' + date);
var gdt1 = new GlideDateTime(date);
gdt1.addDaysUTC(-180);
var gdt2 = gdt1.getDate();
gs.info('ADD Date ' + gdt2);
var dgStart = gdt2;
gs.print(dgStart)
var noDuplicates= "035654444546d46df"
var gr=new GlideRecord('sys_user');
gr.addActiveQuery()
gr.addEncodedQuery('sys_idIN'+noDuplicates);
gr.addEncodedQuery('u_nowit_survey_date>='+dgStart) //// need help with this line of script.
gr.query()
while(gr.next()){
gs.print(gr.name);
}
How to check date is at or after dgstart.
Please help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 03:33 AM
You can use this relative condition
u_nowit_survey_dateRELATIVEGT@dayofweek@ago@180
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 03:38 AM
The condition looks fine for at or after, seems to me you have copied the query from the list filter.
gr.addEncodedQuery('u_nowit_survey_date>='+dgStart)
Is it not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 03:43 AM
Actually condition fails for the date field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2022 03:50 AM
Hi,
is this script is the exact code there are many syntax errors
If you want give date condition as per your requirement you can use relative condition.
Hope you it helps you or let us know if you have any challenge.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar