- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago - last edited 5 hours ago
@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.
List view matches with the report dynamically.
Hope this helps.
Let me know if it worked.
Regards,
Vikas K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Thank you
