scripting query Date field

aksh3
Giga Guru

Hello Experts,

 

I am having query above the date field. how to apply the date filter with "at of after" condition.

@Ankur Bawiskar 

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.

5 REPLIES 5

palanikumar
Mega Sage

You can use this relative condition

u_nowit_survey_dateRELATIVEGT@dayofweek@ago@180

Thank you,
Palani

Muhammad Khan
Mega Sage
Mega Sage

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?

Actually condition fails for the date field.

Pavankumar_1
Mega Patron

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.

find_real_file.png

 

Hope you it helps you or let us know if you have any challenge.

Please Mark Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar