Can I filter a datetime field with a javascript snippet?

tt-jtw
Kilo Expert

I have a report on which I want to dynamically change the datetime filter based on other conditions.   I can write a script include to return the datetime value to filter.   But am I able to create a filter condition on a datetime field that uses javascript?

I know I can do this on string field types -- like:

Name | is | javascript:mycustomfunction();

But on datetime fields, the condition builder suggests preset values like Today, Yesterday, Tomorrow, etc..   I don't see an opportunity to type in a "javascript: ..." string.

6 REPLIES 6

Gurpreet07
Mega Sage

ignore these preset values and just type javascript:function_name in there , it should work


I am unable to type any freeform text in the dropdown field that contains the preset values.   Is there a trick to that?


Yes, in reports we are not able to change the URL but in Record Lists we could edit the top URL.Like below


incident_list.do?sysparm_query=sys_created_on>javascript:gs.daysAgoEnd(1)


Troy Riblett
Giga Guru

The below works, but it is a bit.. Hacky..

That being said, I found myself needing to call a script on dates to deal with our business' concept of "business days" so I found a solution for this.

1. Go into the report and set the field and condition to check against
find_real_file.png

2. Right click the selection field and inspect the element

find_real_file.png

3. Expand the select

find_real_file.png

4. Create another option and set the value to what you want. Note that the inner text doesn't matter, just the value (If you are in Firefox, I find it easiest to right click another option and then choose duplicate)

find_real_file.png

5. Select the option in the drop-down now that you have created it. Then save the report

 

find_real_file.png

6. My working example looks like this

find_real_file.png

 

Again, this feels a bit hacky at best. However, all of the other options they give are hardcoded javascript calls, so I guess this isn't that much worse..