only HR group members have to submit the full employee user creation

vsaikiran
Tera Contributor

Hello All,

1.I've a catalog item,where the request type is a drop down which have the values "software","Hardware","peripherals", and "User Account Management".

2.Now,only the admins or "HR members" or "RMS members" can be able to see the "User Account Management".

3.If  "User Account Management" is selected,we've a drop down down containing the values "Employee User creation" and "contractor worker-user creation".

 

Now  I want a)if logged in user is admin or Hr member, "Employee User creation" should be visible.

b)If the logged in user is admin or RMS member  "contractor worker-user creation" should be visible

 

3 REPLIES 3

Rafael Batistot
Kilo Patron

Hi @vsaikiran 

 

May you try user catalog client scrip onLoad

 

See the code example:

 

function onLoad() {
var userHasAccess = false;

// Check roles of logged-in user
if (g_user.hasRole('admin') || g_user.hasRole('hr_member') || g_user.hasRole('rms_member')) {
userHasAccess = true;
}

// If user does not have access, remove "User Account Management"
if (!userHasAccess) {
g_form.removeOption('<variable_internal_name>', 'User Account Management');
}
}

Hello Rafael,

Thank you for the reply. Here, can you please help me with the sys_id's rather than the roles.

vsaikiran
Tera Contributor

I wrote a code like the below, but hard luck for me

 

function onLoad() {
    var hrGroupSysId = 'f4d4621b3500fe1018ad76499d61310c'; // HR/Insurance
    var rmsAdminSysId = 'd625dccec0a8016700a222a0f7900d06'; // Service Desk

    // Dropdown variable names
    var requestType = 'request_type';
    var variableName = 'user_creation1';

    var userGroups = g_user.groups || [];

    var isHR = userGroups.indexOf(hrGroupSysId) !== -1;
    var isRMS = userGroups.indexOf(rmsAdminSysId) !== -1;
    var isAdmin = g_user.hasRole('admin');

    // Restrict "account" option → only HR, RMS, or Admin can see it
    if (!isHR && !isRMS && !isAdmin) {
        alert('no access for this variable');
        g_form.removeOption(requestType, 'account');
    }

    // Restrict contractors (value = '2') → only HR or Admin can see
    if (!isHR && !isAdmin) {
        g_form.removeOption(variableName, '2');
    }

    // Restrict full-time employees (value = '1') → only RMS or Admin can see
    if (!isRMS && !isAdmin) {
        g_form.removeOption(variableName, '1');
    }
}