Creating a Dynamic Filter

Back in the day, the only way we had to create cool dynamic filters was by having filters that read “User is javascript:gs.getUserID()”. These days, there’s a better way!

Dynamic Filter
The Explanation

It’s possible now to use the “Dynamic” options to create URLs and filters that don’t reveal that they’re using JavaScript. This helps provide a better user experience, as well as make security teams happier, as they worry less about code injection in URLs if they don’t see JavaScript being passed directly.

In order to create a dynamic filter, we still have to take the steps of the old days, and then just go one step further.

In order to show how, I’ll run you through an example:

The Example

  1. Create a Script Include named “getHRUsers”
  2. In that Script Include, put this (and only this) as the script body:
    function getHRUsers() {
         var users = new Array();
         var userRole = new GlideAggregate("sys_user_has_role");
         userRole.addQuery("", "STARTSWITH", "hr_");
         while( {
         return users;
  3. In the left hand navigation, go to Dynamic Filter Options.
  4. Create a New Record, and fill it in like so:
    • Label: an HR User
    • Script: getHRUsers()
    • Field Type: Reference
    • Referenced table: User
    • Order: 500
    • Available for Filter: True
    • Available for Default: True

That’s it! Now give it a try!

Categories: Developers, Tips and Tricks

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: