Encoded Query Not Working When Adding GOTO Date Condition

Aditya40
Tera Contributor

 

Hi Community,

I'm trying to build an encoded query in GlideRecord that combines multiple conditions across sys_class_name, sys_updated_by, and a relative date filter. Here's the query:

 

 
gr.addEncodedQuery('sys_class_name=incident^ORsys_class_name=problem^sys_updated_by=javascript:gs.getUserName()^GOTOsys_updated_onRELATIVEGT@hour@ago@24');

The issue is that this query does not return any results, but if I remove the GOTO part, like this:

gr.addEncodedQuery('sys_class_name=incident^ORsys_class_name=problem^sys_updated_by=javascript:gs.getUserName()');

…it works fine.

I’m not sure if the problem is with how I’m using GOTOsys_updated_onRELATIVEGT@hour@ago@24 

, or if this is incompatible with GlideRecord.

Any insights or suggestions would be appreciated!

Thanks in advance.

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @Aditya40 ,

I have tried the same query you've shared and it's working fine

 

ChaitanyaILCR_0-1750946388986.png

 

do you have data with that filter ?

you filter is this 

try to copy the filter from the condition builder

 

ChaitanyaILCR_2-1750946486595.png

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Aditya40 

GOTO keyword won't work in GlideRecord

try this and use relative date filter

var gr = new GlideRecord('your_table');
var now = new GlideDateTime();
var last24 = new GlideDateTime();
last24.addHoursUTC(-24);

gr.addEncodedQuery('sys_class_name=incident^ORsys_class_name=problem^sys_updated_by=' + gs.getUserName() + '^sys_updated_on>=' + last24.getValue());
gr.query();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

OlaN
Giga Sage
Giga Sage

Hi,

One thing you can and should do when working with encoded queries, is to use the condition filter breadcrumb on the list view of the records you want to filter.

By rightclicking this, and copy the query you will get the result you want.

See attached image.

list-query-condition-builder.png

Chaitanya ILCR
Kilo Patron

Hi @Aditya40 ,

I have tried the same query you've shared and it's working fine

 

ChaitanyaILCR_0-1750946388986.png

 

do you have data with that filter ?

you filter is this 

try to copy the filter from the condition builder

 

ChaitanyaILCR_2-1750946486595.png

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya