- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 09:52 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 11:05 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 11:04 PM
You can't use the object "gs" in a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 11:05 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2018 11:27 PM
Thank you! This solved my issue. Much appreciated.