
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
05-10-2020 02:08 AM - edited 08-03-2024 07:37 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Dynamic Filters, a functionality within ServiceNow that has been around for a while now. Dynamic Filters is a bit underutilized in my opinion. We probably all now Dynamic Filters like "Assigned to is (dynamic) Me". Or when you are not familiar with Dynamic Filters, common appliance of filters like " assigned_to=javascript:gs.getUserID()".
Though did you know, you can create Dynamic Filters yourself? That's not a protected/hidden ServiceNow gem?
Case
While reading this, you might not immediately think of case where a new Dynamic Filter would be helpful. Looking at an out-of-the-box instance, everyone has the delegates functionality available. So what if I want to check Incidents, where the caller or assigned to is a user who has set me as his/here delegate? A nice case for applying a Dynamic Filter!
The delegate set:
Creating a Dynamic Filter
Dynamic Filters contain two pieces. One is the Dynamic Filter Option itself [sys_filter_option_dynamic]. Two is the Script field which contains JavaScript or a Script Include [sys_script_include].
Out-of-the-box [Orlando release], ServiceNow instances are provided with 88 Dynamic Filter Options.
Script Include
First, the Script Include. A Client callable Script Include with name getIAmDelegate. In this Script Include we will query the Delegates table [sys_user_delegate], for Delegate is me (gs.getUserID()) and where the start and end data are within range.
function getIAmDelegate() {
var grDelegate = new GlideRecord('sys_user_delegate');
grDelegate.addQuery('delegate', gs.getUserID());
grDelegate.addQuery('starts', '<=', new GlideDateTime());
grDelegate.addQuery('ends', '>=', new GlideDateTime());
grDelegate._query();
var delegateArr = [];
while(grDelegate._next()) {
delegateArr.push(grDelegate.getValue('user'));
}
return delegateArr;
}
Dynamic Filter Option
We would like to apply this filter on Lists. Therefore we need to check the checkbox Available on filter. This way, the Dynamic option can be selected as an operand in a filter. Other available options are Available for default and Available for ref qual. You could also limit the Dynamic option based on roles. Because this is a filter on a User [sys_user] reference field, we also need to set the Field type and Referenced table according to this.
Result
When we would navigate to for example the Incident List, now there should be a new operant on the User reference fields. Fields like caller and assigned_to.
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Quint Technology
1x ServiceNow Developer MVP
1x ServiceNow Community MVP
---
- 24,701 Views