- 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 10:00 PM
Hi jaredholm,
Can you try this one?
I have used your script, and added some logic:
Get User ID, Check if user is member of the group and then set the visibility for the required fields.
function onLoad() {
var usr = g_user.getUserID();
if (usr.isMemberOf('ITSS IT Compliance')){
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);
}
}
Hit like if it solves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 10:26 PM
This solution does not work. The line "var usr = g_user.getUserID();" is not a valid line of code in a client script and it messes up the client script. With it, all users can see the variables; without it, only admins can see the variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 11:05 PM
Hi,
For this you have to write Display BR on catalog task table with the below code and use g_scratch pad in client script.
In Display BR
g_scratchpad.isMember = gs.getUser().isMemberOf('ITSS IT Compliance');
In onLoad Client script
if(!g_scratchpad.isMember)
{
g_form.setVisible('variables.score_1', false);
g_form.setVisible('variables.score_2', false);
g_form.setVisible('variables.score_3', false);
g_form.setVisible('variables.score_4', false);
g_form.setVisible('variables.score_5', false);
g_form.setVisible('variables.score_6', false);
g_form.setVisible('variables.score_total', false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2018 10:43 PM
The Function " var usr = g_user.getUserID();" works well for me. It returns sys_id
You can also try putting it like this
if(gs.getUser().isMemberOf('ITSS IT Compliance'))
Here is the URL for article to show the function utilization