how to query records "before last 13 months" - encoded query

maronis
Mega Guru

Hi folks, 

I am working on a Script scheduled job that would clear records on a table based on their date of creation < last 13 months

I would use a Glide record and am trying to construct the Encoded query. More specifically I am trying to code the "<last 13 months" into my query but it does not work. 

For example, in standard, "last 12 months" condition is available but not "last 13 months"

I have been tinkering with the encoded query:

- "sys_created_on<javascript:gs.beginningOfLast13Months()" -> does not work

- "sys_created_on<javascript:new GlideDateTime().addMonthsLocalTime(-13);" -> does not work

I have a workaround which consists of converting 13 months into days but I 'd prefer to user it as a last resort:

- "sys_created_on<javascript:gs.daysAgo(396)" -> ok if not a better option

 

Thank you in advance for your help!

 

Maron

1 ACCEPTED SOLUTION

maronis
Mega Guru

Hi,

 

I eventually found out the answer. Sorry for the late update. I don't connect often:

var encodedQuery="endISNOTEMPTY^end<javascript:gs.monthsAgo(13)^NQendISEMPTY^sys_created_on<javascript:gs.monthsAgo(13)";

 

regards,

View solution in original post

2 REPLIES 2

sachin_namjoshi
Kilo Patron
Kilo Patron

you can create your own dynamic filter and use it in filter.

 

https://docs.servicenow.com/bundle/london-platform-user-interface/page/use/using-lists/task/t_DynamicFilterOptions.html

 

REgards,

Sachin

maronis
Mega Guru

Hi,

 

I eventually found out the answer. Sorry for the late update. I don't connect often:

var encodedQuery="endISNOTEMPTY^end<javascript:gs.monthsAgo(13)^NQendISEMPTY^sys_created_on<javascript:gs.monthsAgo(13)";

 

regards,