Explain this encoded Query

Asha Pathak
Tera Contributor

Hello Community!

 

Please explain below encoded query

2 REPLIES 2

Runjay Patel
Giga Sage

Hi @Asha Pathak ,

 

Encoded query state that 

Retrieve all active records where the start date falls within the current day (from 12:00 AM to 11:59 PM).

 

You can do this using glide record like below.

 

var gr = new GlideRecord('table_name');
gr.addQuery('start', '>=', gs.beginningOfToday());
gr.addQuery('start', '<=', gs.endOfToday());
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
    gs.print(gr.getValue('start'));
}

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Robbie
Kilo Patron
Kilo Patron

Hi @Asha Pathak 

 

This encoded query is simply listing records on the table where you're running the query from where the field name 'start' is on Today and where active is true.

The below screen shot using the Incident table and the 'work_start' field (table display value 'Actual time') should help:

 

Encoded query example: work_startONToday@javascript&colon;gs.beginningOfToday()@javascript&colon;gs.endOfToday()^active=tru...

 

Screenshot 2024-11-25 at 12.35.45.png

 

The javascript handle of beginningOfToday() and enOfToday() methods that you see within the Encoded Query are simply what's required at the database level.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie