Display variable based on Group membership

alhicks
Tera Guru

I'm trying to display a variable on catalog view, item view and task view, only if the logged in user is a member of a certain group.     We'd like to hide the variable from admins too.

Trying the below script in UI Policy but not having any luck..:(

function onCondition() {

var grp = new GlideRecord('sys_user_grmember');    

      grp.addQuery('group', '=', '1a22d5c1130bcf001454b9722244b01d'); //payroll matrix

      grp.addQuery('user', g_user.userID);

      grp.query();    

      if(grp.next()){  

     

      g_form.setDisplay('ssn', true);  

     

          }

}

 

find_real_file.png

1 ACCEPTED SOLUTION

Thank you Jaspal and David for the replies.   I ended up doing a display business rule and an onLoad client script.



(function executeRule(current, previous /*null when async*/) {




g_scratchpad.grp = gs.getUser().isMemberOf('Payroll Matrix');




})(current, previous);



function onLoad() {



if(g_scratchpad.grp == true)




{


g_form.setDisplay('ssn', true);




}


else


{


      g_form.setDisplay('ssn', false);




    }


}


View solution in original post

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi Andrea,



Did you try using g_form.setVisible() instead of g_form.setDisplay(). Also, you can have a Client script written onLoad() instead of UI policy.


Thank you Jaspal and David for the replies.   I ended up doing a display business rule and an onLoad client script.



(function executeRule(current, previous /*null when async*/) {




g_scratchpad.grp = gs.getUser().isMemberOf('Payroll Matrix');




})(current, previous);



function onLoad() {



if(g_scratchpad.grp == true)




{


g_form.setDisplay('ssn', true);




}


else


{


      g_form.setDisplay('ssn', false);




    }


}


Dubz
Mega Sage

HI Andrea,



I think you might have to put this in an onLoad client script, in a UI policy the script section will execute once the conditions have been matched, the script you're adding is the condition itself.