Hide an option in reference field based on user role on record producer

Anupriya_11
Tera Contributor

Hi Team , I have a requirement to hide one option(ex: A)  in reference field based on user role, for non-ITIL users option should not be visible on the form. Could you please help me on how to achieve this. 

I have tried the on load script but its not working.

function onLoad() {
   //Type appropriate comment here, and begin script below
  var service= g_form.getValue('u_services');
  var role =g_user.hasRole('itil');
   //if (!g_user.hasRole('itil')){
    if(role == false){
    alert('service'+ service);
// Get the multiple choice field element (replace 'field_name' with the actual field name)
g_form.removeOption(service,'Help');
 
}
}
 
Thanks
11 REPLIES 11

Hi @Ankur Bawiskar ,

I have tried the above script , it is  filtering the only condition with users location , rest is not working. could you please help on this issue.

Jagadish Sanadi
Kilo Sage

var tcc = new GlideAjax('script_Include_name');
tcc.addParam('sysparm_name', 'function');
tcc.addParam('sysparm_user', passYourValue);
tcc.getXML(callBack);


function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');

if (answer == 'true') {
g_form.removeOption('variable_name','variable_value','Variable Text');
}


var user = this.getParameter("sysparm_user");
var checkUser = new GlideRecord('sys_user_grmember');
checkUser.addQuery('user', user);
checkUser.addQuery('group', gs.getProperty('test')); // replace <sys_id_group> with actual sys_id of group.
checkUser.query();
if (checkUser.next()) {
return true;
} else {

return false;
}

 

If my response helped, please mark it as the accepted solution 
Thanks

Jagadish