Make HR Services invisible in the drop down picker

Andre Jones
Tera Expert

Hello,

 

I have a requirement that needs to make the following changes to the HR Service drop down picker to make them invisible to specific groups that I've created. I created two groups Tech Lead and Tech Associate, when any person who is a member of those groups logs on and selects the HR Service drop down they should not see any on the following HR Services I've created. "High Visibility Report" and "Unemployment" that I created under the "Employee Relations" COE. The COE Security Figuration does not provide anything to prevent them from seeing and creating the HR Service case. Thank you for any assistance you can provide. Take a look at the screenshot I have. 

 

AndreJones_0-1702046945044.png

 

8 REPLIES 8

jMarshal
Mega Sage
Mega Sage

You should be able to do this with an onLoad Client Script! First, glide to sys_user_grmember to see if the logged in user is a member of the group. Keep in mind that you'll need to consider cases when they may be a member of both groups (which one matters more?)...then you can hide options for the select list drop-down. Here is an example to get you started:

 

 

 

 

function onLoad() {
 
    var currentUser = g_user.getUserName();
    var group = "Group Name"; // replace with actual name of group which can't see the variables.
    var memberOfGroup = isUserMemberOfGroup(currentUser, group);

    if (memberOfGroup) {
        hideChoices('variable_name'); // where 'variable_name' with the actual name of your list variable on the form
    }
}

function isUserMemberOfGroup(user, groupName) {
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', user);
    gr.addQuery('group.name', groupName);
    gr.query();
    return gr.hasNext();
}

function hideChoices(variableName) {
    var variable = g_form.getControl(variableName); // where 'variable_name' with the actual name of your list variable on the form
    var choicesToHide = ['value_1', 'value_2']; // where 'value_1' and 'value_2' are the values of the choice list that you want to hide. you can expand this list to more variables as comma separated.

    for (var i = 0; i < choicesToHide.length; i++) {
        variable.removeOption(choicesToHide[i]);
    }
}

 

 

 

 





Rajesh_Bhise
Tera Guru

Hello @Andre Jones,

 

I suggest to  use below onload client script on HR case form to get the solution for your requirement.

 

 

function onLoad() {
 
    var gUser = g_user.getUser();
    var groupid = "Group sys_id"; // add sys id of desired group, you can call system property as well with sys id of group.
    var memberOfGrp = getGroupOfUser(gUser, groupid);

    if (memberOfGrp) {
        g_form.removeOption('hr_service',<option1>) // option1 can be your choice name of hr service field
        g_form.removeOption('hr_service',<option2>) // option2 can be your choice name of hr service field
        g_form.removeOption('hr_service',<option3>)  // option3 can be your choice name of hr service field
    }
}

function memberOfGrp(user, group) {
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', user);
    gr.addQuery('group', group);
    gr.query();
    if(gr.nextext()){
    return true;
}
}

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer✔️ and helpful👍, this may help other community users to follow correct solution in future.

Happy to help you in future.

 

Thank you,
Rajesh

michaelj_sherid
ServiceNow Employee
ServiceNow Employee

@Andre Jones Just a word of caution, I believe any solution you find that functions in the UI16 will be different from how you will accomplish this in the Configurable Workspace. If you are using, or plan to use the Workspace, you will want to consider this as well.

 

Regards,

Mike

Thank you @michaelj_sherid , I am planning on using Agent workspace. What is the alternative route to take then? 

 

@Rajesh_Bhise @jMarshal