Can I filter a datetime field with a javascript snippet?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2015 06:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2015 11:11 PM
ignore these preset values and just type javascript:function_name in there , it should work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2015 05:03 AM
I am unable to type any freeform text in the dropdown field that contains the preset values. Is there a trick to that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2015 05:39 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 04:15 PM
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
2. Right click the selection field and inspect the element
3. Expand the select
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)
5. Select the option in the drop-down now that you have created it. Then save the report
6. My working example looks like this
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..