Display user groups and role in RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 11:25 PM
Hello,
I have a catalog item for offboarding and my requirement is to display the user(request for) current groups and roles under the specific group on the worknotes of the RITM. I tried in flow designer the on available is roles but when i submit the request cant display the roles in the work notes. I need help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 12:07 AM
Hi @Community Alums
Create business rule on Requested Item [sc_req_item] table as shown below
Add below script in the 'Advanced' tab of the business rule
(function executeRule(current, previous /*null when async*/) {
// Get the sys_id of the user for whom the request is made
var userSysId = current.requested_for;
// Initialize arrays to hold groups and roles
var groups = [];
var roles = [];
// Query the GroupMember table to get the groups for the user
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('user', userSysId);
grMember.query();
while (grMember.next()) {
var groupName = grMember.group.getDisplayValue();
groups.push(groupName);
}
// Query the UserRole table to get the roles for the user
var grRole = new GlideRecord('sys_user_has_role');
grRole.addQuery('user', userSysId);
grRole.query();
while (grRole.next()) {
var roleName = grRole.role.getDisplayValue();
roles.push(roleName);
}
// Combine groups and roles into a single string
var worknotesText = 'Groups:\n' + groups.join('\n') + '\n\nRoles:\n' + roles.join('\n');
// Append the information to the worknotes of the RITM
current.work_notes = worknotesText;
current.update();
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2024 12:17 AM