Explain this encoded Query

Rajkumar Bommal
Tera Contributor
var.addEncodedQuery(' sys_updated_onONToday@javascript: gs.beginningOfToday()@javascript: gs.endOfToday()');
why we are using encoded query and @javascript syntax
2 ACCEPTED SOLUTIONS

Maddysunil
Kilo Sage

@Rajkumar Bommal 

The addEncodedQuery function allows you to add a query to a GlideRecord object using an encoded query string. An encoded query string is a string that represents a query in a URL-friendly format. This format is typically used in URLs to represent complex queries with special characters or operators.

The @javascript: syntax is a way to execute JavaScript functions within the encoded query string. This is useful when you need to perform dynamic calculations or comparisons as part of your query.

In your specific example:

The sys_updated_on field is being compared against a dynamic range, from the beginning of today (gs.beginningOfToday()) to the end of today (gs.endOfToday()). This ensures that you're querying for records where the sys_updated_on field falls within the current day.

Using @javascript: allows you to execute ServiceNow's gs (GlideSystem) functions directly within the encoded query string, enabling dynamic date calculations.

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

View solution in original post

abhishekdalvi
Tera Guru

Hi @Rajkumar Bommal ,

Encoded query syntax is used to build the complex query to filter the data. This will help us to reduce the mistake happens while and / or operations in the query using addQuery() or addOrCondition() syntax.


However gs is the global object in ServiceNow and we use beginningOfToday() & endOfToday() functions.

 

beginningOfToday() :

Retrieves the date and time for the end of today in GMT & return value is string in GMT in the format yyyy-mm-dd hh:mm:ss.


endOfToday() :

Retrieves the date and time for the end of today in GMT & return value is string in GMT in the format yyyy-mm-dd hh:mm:ss.

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.

 

Thank you!

Regards,
Abhishek Dalvi

View solution in original post

2 REPLIES 2

Maddysunil
Kilo Sage

@Rajkumar Bommal 

The addEncodedQuery function allows you to add a query to a GlideRecord object using an encoded query string. An encoded query string is a string that represents a query in a URL-friendly format. This format is typically used in URLs to represent complex queries with special characters or operators.

The @javascript: syntax is a way to execute JavaScript functions within the encoded query string. This is useful when you need to perform dynamic calculations or comparisons as part of your query.

In your specific example:

The sys_updated_on field is being compared against a dynamic range, from the beginning of today (gs.beginningOfToday()) to the end of today (gs.endOfToday()). This ensures that you're querying for records where the sys_updated_on field falls within the current day.

Using @javascript: allows you to execute ServiceNow's gs (GlideSystem) functions directly within the encoded query string, enabling dynamic date calculations.

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

abhishekdalvi
Tera Guru

Hi @Rajkumar Bommal ,

Encoded query syntax is used to build the complex query to filter the data. This will help us to reduce the mistake happens while and / or operations in the query using addQuery() or addOrCondition() syntax.


However gs is the global object in ServiceNow and we use beginningOfToday() & endOfToday() functions.

 

beginningOfToday() :

Retrieves the date and time for the end of today in GMT & return value is string in GMT in the format yyyy-mm-dd hh:mm:ss.


endOfToday() :

Retrieves the date and time for the end of today in GMT & return value is string in GMT in the format yyyy-mm-dd hh:mm:ss.

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me.

 

Thank you!

Regards,
Abhishek Dalvi