Why below script/ query is not working after passing 2 dates in addEncodedQuery ?

Virendra K
Kilo Sage

Hi All,

 

I am trying to pass 2 dates in addEncodedQuery but its not working. There is some mistake while passing the dates parameter but not clear on this. Please suggest.

 
             var output=[];
             var gr1 = new GlideRecord('cmn_schedule_span');
             var query2= "schedule.type=blackout^schedule.name=Central Winter Break^u_start_time>=javascript&colon;gs.dateGenerate('2024-09-16','09:08:46 AM')^u_end_time<=javascript&colon;gs.dateGenerate('2024-09-17','09:08:46 AM')";
            gr1.addEncodedQuery(query2);
            gs.print('VIREN : Q2 = ' + query2);
            gr1.query();
            while (gr1.next()) {
                gs.print("VIREN Passed");
                output.push(gr1.name+ ' -- '+ gr1.start_date_time + ' to ' + gr1.end_date_time);
                }
           gs.print('VIREN TESTING Result Before Output is ' + output);

 

6 REPLIES 6

ShubhamGarg
Kilo Sage

Hello @Virendra K ,

 

Can you change the query2 and check?

 

FROM: schedule.type=blackout^schedule.name=Central Winter Break

TO: schedule.type=blackout^name=Central Winter Break

 

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

Hi @ShubhamGarg 

Thanks for the reply.

Query is working with "schedule.type=blackout^schedule.name=Central Winter Break" but if we adds "^u_start_time>=javascript&colon;gs.dateGenerate('2024-09-16','09:08:46 AM')^u_end_time<=javascript&colon;gs.dateGenerate('2024-09-17','09:08:46 AM')" then its not working. so problem is in date parameters.

 

Hello @Virendra K ,

I see you have used u_start_time and u_end_time. Is it correct? Are you using custom fields?

Reason being, we have Out of box fields Start date time (start_date_time) & End date time (end_date_time) for this table.

 

https://<instance-name>.service-now.com/sys_dictionary_list.do?sysparm_query=name%3Dcmn_schedule_span%5Ecolumn_label%3DEnd%20date%20time%5EORcolumn_label%3Dstart%20date%20time&sysparm_first_row=1&sysparm_view=

 

ShubhamGarg_0-1726506848335.png

 

Hope this helps. Let me know if it doesn't.

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

Sumanth16
Kilo Patron

HI @Virendra K , 

 

Please refer  below thread:

https://www.servicenow.com/community/developer-forum/addencodedquery-for-date-field-not-working/m-p/...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda