How do I create a Client Script that hides Variables on the Catalog Task form from all users except a specific group?

jaredholm
Kilo Contributor

I am looking to create a Client Script that only allows users with the group "ITSS IT Compliance" to view variables on a catalog task form. I currently have this as a test script, but the top half of the if statement is incorrect, hiding the variables from all users except those with the admin role. I need it to allow users with the group "ITSS IT Compliance" to view these variables, but there are no unique roles to filter this group on:

function onLoad() {
      //Get user's group
      if (g_user.hasRole('admin') == true){
     
     } else{ //Set scoring variables to invisible
          g_form.setVisible('score_1', false);
          g_form.setVisible('score_2', false);
          g_form.setVisible('score_3', false);
          g_form.setVisible('score_4', false);
          g_form.setVisible('score_5', false);
          g_form.setVisible('score_6', false);
         g_form.setVisible('score_total', false);
    }
}

The bottom half works. A colleague of mine suggested creating a business rule that gets the user's groups and then calling that business rule, but I am unsure of how this would work, and am hoping for an easier way to do this. If there is no other way, could you explain to me how write the business rule to make this client script work?

Thanks in advance.

1 ACCEPTED SOLUTION

Inactive_Use945
Kilo Expert

Create a display Business rule with script as. Place the below script between function templates in script body.

 

g_scratchpad.grp = gs.getUser().isMemberOf('ITSS IT Compliance');  

 

 

Now update the client script as

 

function onLoad() {

  if (g_scratchpad.grp)){

  g_form.setVisible('score_1', true);
          g_form.setVisible('score_2', true);
          g_form.setVisible('score_3', true);
          g_form.setVisible('score_4', true);
          g_form.setVisible('score_5', true);
          g_form.setVisible('score_6', true);
         g_form.setVisible('score_total', true);

}

    else{ //Set scoring variables to invisible
          g_form.setVisible('score_1', false);
          g_form.setVisible('score_2', false);
          g_form.setVisible('score_3', false);
          g_form.setVisible('score_4', false);
          g_form.setVisible('score_5', false);
          g_form.setVisible('score_6', false);
         g_form.setVisible('score_total', false);
    }
}

 

 

View solution in original post

7 REPLIES 7

You can't use the object "gs" in a client script.

Inactive_Use945
Kilo Expert

Create a display Business rule with script as. Place the below script between function templates in script body.

 

g_scratchpad.grp = gs.getUser().isMemberOf('ITSS IT Compliance');  

 

 

Now update the client script as

 

function onLoad() {

  if (g_scratchpad.grp)){

  g_form.setVisible('score_1', true);
          g_form.setVisible('score_2', true);
          g_form.setVisible('score_3', true);
          g_form.setVisible('score_4', true);
          g_form.setVisible('score_5', true);
          g_form.setVisible('score_6', true);
         g_form.setVisible('score_total', true);

}

    else{ //Set scoring variables to invisible
          g_form.setVisible('score_1', false);
          g_form.setVisible('score_2', false);
          g_form.setVisible('score_3', false);
          g_form.setVisible('score_4', false);
          g_form.setVisible('score_5', false);
          g_form.setVisible('score_6', false);
         g_form.setVisible('score_total', false);
    }
}

 

 

Thank you! This solved my issue. Much appreciated.