Reporting: Dynamic filter for Updated field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
I wanted to apply the dynamic filter for updated field.The requirement is:
To edit the "Updated Between" from my static date to Yesterday 18:30 and today 07:30. I understand that the following code would do this; however, I'm not able to find where I can add javascript.
javascript:gs.beginningOfYesterday().addHours(18).addMinutes(30)
javascript:gs.beginningOfToday().addHours(07).addMinutes(30)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
share screenshot where you want to apply this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @mounika107 ,
You’re trying to make your Updated Between filter dynamic in ServiceNow so it always runs between yesterday at 18:30 and today at 07:30.
Key Detail:
The JavaScript you wrote (gs.beginningOfYesterday()...) is correct, but you don’t paste raw JavaScript into the filter condition builder. ServiceNow’s list filters and reporting UI don’t accept inline JS. Instead, you have a few options depending on where you want this logic to live.
You can use that Javascript:
- Business Rules / Script Includes / Scheduled Jobs:
Example:-
var gr = new GlideRecord('incident');
gr.addQuery('sys_updated_on', 'BETWEEN',
gs.beginningOfYesterday().addHours(18).addMinutes(30),
gs.beginningOfToday().addHours(7) .addMinutes(30)
);
gr.query();
This works in background scripts, business rules, or scheduled jobs.
- Dynamic Filters (Encoded Queries):
- In the filter builder UI, you can’t insert JS. Instead, you create a Dynamic Filter Option (via System Definition > Dynamic Filter Options) and point it to a Script Include that returns your date range.
- That way, users can select “Updated Between Yesterday 18:30 and Today 07:30” as a reusable filter.
- Reports / Performance Analytics:
- For reports, you can define a relative date condition (like “Last 1 day” or “Today”) but not exact times. If you need exact times, you’ll need a scripted data source or scheduled job.
So Recommended Approach in your case:
Since you want a reusable filter, the cleanest way is:
- Create a Dynamic Filter Option for sys_updated_on.
- Back it with a Script Include that returns the two GlideDateTime values (yesterday 18:30 and today 07:30).
- Then in your list/report filter, you’ll see your custom option alongside “Today”, “Yesterday”, etc.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Thanks,
Anupam.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
