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.

Display user groups and role in RITM

Not applicable

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.

2 REPLIES 2

Iraj Shaikh
Mega Sage

Hi @Community Alums 

Create business rule on Requested Item [sc_req_item] table as shown below
Screenshot 2024-01-22 at 1.34.47 PM.png

 

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.

Not applicable

Hello @Iraj Shaikh 

Can i ask why the worknotes is repeating?