Hide a variable on record producer based on role of logged in user

rambo1
Tera Guru

Hi I have a field on record producer which is in customer service scope.

that field should only visible to user with role ' sn_customerservice.customer_admin'.

How do I achieve this?

7 REPLIES 7

does this work in scoped application?

yes UI policies can be created in scoped application.

Willem
Giga Sage
Giga Sage

Can you try:

  • replace set field name here with your field (technical) name
  • If the field is not and should not be mandatory remove the setMandatory lines below
function onLoad() {
    g_form.setMandatory("set field name here", false);
    g_form.setVisible("set field name here", false);
    if (g_user.hasRole('sn_customerservice.customer_admin')) {
        g_form.setMandatory("set field name here", true);
        g_form.setVisible("set field name here", true);
    }
}

 

It will set the field visible if the user has the role 'sn_customerservice.customer_admin' or if the user is an admin.

 

Things to check:

  • Are there any other client scripts that set this field to show or not?
  • Are there any UI Policies that set this field to show or not?
  • You can temporarily include an alert on the condition and check the result like so:
function onLoad() {
    alert(g_user.hasRole('sn_customerservice.customer_admin'));
    g_form.setMandatory("set field name here", false);
    g_form.setVisible("set field name here", false);
    if (g_user.hasRole('sn_customerservice.customer_admin')) {
        g_form.setMandatory("set field name here", true);
        g_form.setVisible("set field name here", true);
    }
}