Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Workspace records view restriction based on group members

sukran
Mega Sage

we want to show the my asset records depends on support group users in workspace , any idea how to achieve this?

 

sukran_0-1743861232333.png

 

6 REPLIES 6

Omender Singh
Tera Guru

Yes, you can achieve this in ServiceNow Workspace by applying dynamic filters and data policies to control which asset records a user sees, based on their Support Group membership.

Can you elaborate where I can apply thats needs to fucntion on workspace . Data polices normally works on form level, how to do in workspace?

I found a it in UI builder to set data policy but can we do modify OOTB workspace ?

swapnali ombale
Kilo Sage

Hi @sukran 

 

To display "My Asset" records in a ServiceNow workspace based on a user's support group, you can use UI Builder and a script to filter records based on the logged-in user's group membership. 
 
Here's a breakdown of the process:
 
1. Identify the Relevant Tables and Fields:
 
  • Asset Table:
    This table stores your asset information (e.g., alm_hardware or cmdb_ci_asset).
  • Support Group Field:
    This field in the asset table links the asset to a specific support group (e.g., a reference field pointing to the sys_user_group table).
  • User Group Membership:
    Determine how users are assigned to support groups (e.g., through the sys_user_grmember table).
     
 
2. Create a Script Include (Optional but Recommended):
  • Create a script include to encapsulate the logic for retrieving the user's support group(s).
  • This script should:
    • Get the currently logged-in user's ID (gs.getUserID()).
    • Query the sys_user_grmember table to find the user's group memberships.
    • Return an array of group IDs. 
       
 
3. Configure the Workspace in UI Builder:
 
  • Select the Asset Table:
    In UI Builder, specify the asset table as the data source for your workspace page.
  • Add a List Filter:
    • Add a list filter to the UI Builder component that displays the asset records.
    • Use the sys_user_grmember table to query the groups the user belongs to.
    • Use the script include (if you created one) to dynamically retrieve the group IDs.
    • Filter the asset records based on the support group field, ensuring that only assets assigned to the user's support groups are displayed.
       
 
4. Example Script Include:
 
JavaScript
 
var MyAssetFilter = {
getSupportGroups: function() {
var user = gs.getUserID();
var userGroups = new GlideRecord('sys_user_grmember');
userGroups.addQuery('user', user);
userGroups.query();
var groupIDs = [];
while (userGroups.next()) {
groupIDs.push(userGroups.getRefRecord('group').getUniqueValue());
}
return groupIDs;
}
};
 
5. Example UI Builder Filter:
 
JavaScript
 
// Assuming you have a field named 'support_group' in your asset table
// and a script include named 'MyAssetFilter'
// and a UI Builder component that displays the asset records

var supportGroups = MyAssetFilter.getSupportGroups();

// Filter the records based on the 'support_group' field
var query = "support_group IN " + supportGroups.join(",");