Issue in encoded query to check dates

Karishma Dubey
Tera Expert

Hi,

I am trying below query to get the users whose start date is today or 15 days from now. However, it is returning users users whose start date is more than 15 days also. Please help.

 

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('u_user_type=EMP^u_ad_effective_startRELATIVEGT@dayofweek@ahead@15^ORu_ad_effective_startONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^u_processed_by_sml=false');
gr.query();
while (gr.next()) {
    gs.print('id '+gr.getValue('user_name'));
}
KarishmaDubey_0-1706634297023.pngKarishmaDubey_1-1706634306313.png

 

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello @Karishma Dubey 

 

Try below query :

 

gr.addEncodedQuery('u_user_type=EMP^u_ad_effective_startRELATIVEGT@dayofweek@ahead@14^u_ad_effective_startRELATIVELT@dayofweek@ahead@15^ORu_ad_effective_startONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^u_processed_by_sml=false');

 

I have tried like below on due date :

 

VishalBirajdar_0-1706678636853.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

4 REPLIES 4

shubhamdubey
Mega Sage

@Karishma Dubey 

 

Hey could you please try this filter condition as per your field .

Might be it would be helpfulfilter.PNG

Tai Vu
Kilo Patron
Kilo Patron

Hi @Karishma Dubey 

Let's give me query a try.

var gr = new GlideRecord('sys_user');
gr.addQuery('u_user_type', 'EMP');
gr.addQuery('u_processed_by_sml', false);
gr.addQuery('u_ad_effective_start', '<=', gs.daysAgo(-15)); //at or before 15 days from now
gr.addQuery('u_ad_effective_start', '>=', new GlideDateTime()); //at or after today
gr.query();
while(gr.next()){
    gs.infor('id: ' + gr.getValue('user_name'));
}

 

Cheers,

Tai Vu

Vishal Birajdar
Giga Sage

Hello @Karishma Dubey 

 

Try below query :

 

gr.addEncodedQuery('u_user_type=EMP^u_ad_effective_startRELATIVEGT@dayofweek@ahead@14^u_ad_effective_startRELATIVELT@dayofweek@ahead@15^ORu_ad_effective_startONToday@javascript&colon;gs.beginningOfToday()@javascript&colon;gs.endOfToday()^u_processed_by_sml=false');

 

I have tried like below on due date :

 

VishalBirajdar_0-1706678636853.png

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ankur Bawiskar
Tera Patron
Tera Patron

@Karishma Dubey 

try script shared by members and share feedback

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