Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Dynamic Filter

adamtoth
Tera Contributor

I am trying to create some reports for a dashboard that would be unique each user that views it. In order to do this I would need to add filters that are dynamic to who is viewing the DB. Adding javascript: gs.getUserName() works for the "Created By" filter. is there another command that would work for doing the same for Assigned To and Assignment Group?

1 ACCEPTED SOLUTION

Anupam1
Mega Guru

To make these fields dynamically filter based on the current user viewing the dashboard, here are some approaches:

 

Dynamic Filtering for "Assigned To:

Use javascript:gs.getUserID(): This returns the sys_id of the current user, which is ideal for filtering reference fields like "Assigned To".

 

Dynamic Filtering for "Assignment Group:

Use a Scripted Reference Qualifier:

var GetUserGroups = Class.create();

GetUserGroups.prototype = {

  initialize: function() {},

  getGroups: function(userID) {

    var groups = [];

    var gr = new GlideRecord('sys_user_grmember');

    gr.addQuery('user', userID);

    gr.query();

    while (gr.next()) {

      groups.push(gr.group.toString());

    }

    return groups;

  },

  type: 'GetUserGroups'

};

  • Then use a reference qualifier like:

javascript:GetUserGroups.getGroups(gs.getUserID())

 

Alternative: Client Script + Reference Qualifier:

  • Use a client script to set a filter on the "Assignment Group" field based on the current user's group membership.
  • This is useful if you want to restrict the dropdown to only groups the user belongs to.

View solution in original post

4 REPLIES 4

Anupam1
Mega Guru

To make these fields dynamically filter based on the current user viewing the dashboard, here are some approaches:

 

Dynamic Filtering for "Assigned To:

Use javascript:gs.getUserID(): This returns the sys_id of the current user, which is ideal for filtering reference fields like "Assigned To".

 

Dynamic Filtering for "Assignment Group:

Use a Scripted Reference Qualifier:

var GetUserGroups = Class.create();

GetUserGroups.prototype = {

  initialize: function() {},

  getGroups: function(userID) {

    var groups = [];

    var gr = new GlideRecord('sys_user_grmember');

    gr.addQuery('user', userID);

    gr.query();

    while (gr.next()) {

      groups.push(gr.group.toString());

    }

    return groups;

  },

  type: 'GetUserGroups'

};

  • Then use a reference qualifier like:

javascript:GetUserGroups.getGroups(gs.getUserID())

 

Alternative: Client Script + Reference Qualifier:

  • Use a client script to set a filter on the "Assignment Group" field based on the current user's group membership.
  • This is useful if you want to restrict the dropdown to only groups the user belongs to.

adamtoth
Tera Contributor

Thank you!

VikMach
Mega Sage

@adamtoth, you can create a script include with the desired filter(s) and then call the script include with the respective functions in the report filter like example below.

 

VikMach_2-1761762679825.png
List view matches with the report dynamically.

VikMach_3-1761762749378.png


Hope this helps.
Let me know if it worked.

Regards,
Vikas K

adamtoth
Tera Contributor

Thank you