Dynamic Filter for last business day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
I have a requirement to add a filter option that would allow our users to return records created on the last business day.
I tried doing this by creating a Script Include to retrieve the last business day (based on a schedule) and then created a Dynamic Filter Option to utilise the script include. However, having read some other community posts, it seems that Date/Time fields cannot be used for Dynamic Filters (despite it being an option!).
Does anyone have any recommendations as to how I might be able to achieve this - is there a way to update the OOTB date/time filters shown below to add this as an option?
Thanks in advance
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @richardyaxl ,
You are on the right track with the Script Include, but I would not use a Dynamic Filter Option for this requirement.
Dynamic Filter Options are designed to work with reference fields. Created, Opened, Updated, Closed, etc. are Date/Time fields, so using a Dynamic Filter Option against those fields is not the correct mechanism.
Recommended approach:
Keep your existing Script Include that calculates the previous business day using GlideSchedule, but expose two values:
- Start of the previous business day
- End of the previous business day
Then use those methods directly in a scripted Date/Time condition.
For example:
sys_created_onBETWEENjavascript:new LastBusinessDayUtil().getLastBusinessDayStart()@javascript:new LastBusinessDayUtil().getLastBusinessDayEnd()
You could also structure it using the Date/Time ON condition if required:
sys_created_onONLast Business Day@javascript:new LastBusinessDayUtil().getLastBusinessDayStart()@javascript:new LastBusinessDayUtil().getLastBusinessDayEnd()
The important part is that the Script Include should calculate the previous business day using the required business schedule instead of simply subtracting one calendar day.
For example:
Monday should return Friday.
Tuesday should return Monday.
The day after a configured holiday should return the previous valid business day.
Weekends and holidays should be handled by the schedule rather than being hard-coded.
Also make sure the schedule timezone is handled correctly, because GlideSchedule can use the schedule timezone or session timezone depending on how it is instantiated.
Why this approach:
The business-day calculation belongs in reusable server-side logic.
The actual filtering should remain a Date/Time condition.
This avoids trying to force a reference-field Dynamic Filter feature onto a Date/Time field and keeps the logic reusable for Created, Opened, Updated, Resolved, Closed, or any other Date/Time field.
I would not modify the OOB Date/Time condition builder just to add "Last Business Day" to the standard Today, Yesterday, This Week, etc. options unless there is a strong business requirement.
Modifying OOB behavior introduces additional upgrade and maintenance overhead.
For reports, another clean option is to create a reusable report or report source with this condition so users do not need to recreate the encoded query manually.
Things to verify:
- Confirm the correct business schedule is being used.
- Confirm weekends and holidays are configured correctly in the schedule.
- Test the calculation on Monday.
- Test the calculation after a holiday.
- Test using the required timezone.
- Return both the start and end Date/Time values.
- Test the encoded query directly against the target table before using it in reports or dashboards.
Official ServiceNow Documentation:
Create a Dynamic Filter Option:
https://www.servicenow.com/docs/r/platform-user-interface/t_DynamicFilterOptions.html
Values for Date/Time Fields:
https://www.servicenow.com/docs/r/platform-user-interface/c_ValuesForDateTimeFields.html
GlideSchedule API:
https://www.servicenow.com/docs/r/xanadu/api-reference/server-api-reference/c_GlideScheduleScopedAPI...
Create a Core UI Date Filter:
https://www.servicenow.com/docs/r/now-intelligence/core-ui-interactive-filters/t_CreateADatePublishe...
Hope this helps!
If this resolves your issue, please mark the response as Helpful and Accept as Solution.
Kind Regards,
Abhishek Pal
