Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 11:41 AM
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(",");