- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2017 08:21 PM
Hi team,
I want to hide a service portal category item for all users NOT belonging to a specific group. I have created a SCRIPT INCLUDE and a CATALOG CLIENT SCRIPT to do this task. I have successfully done it to hide the item for users with a specific service level. But i cannot seem to figure out how to do this for a group as i cannot use isMemberOf() in the client side. I have attached the screen shots i have done for the service levels. Please advise me on how i can hide the specific category item based on the user group.
This is the SERVER SIDE SCRIPT (Script Include)
This is the CATALOG CLIENT SCRIPT
All help is appreciated.
Thank you Team
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2017 10:49 PM
Hi Thiraj,
gs.getUser().isMemberOf('<group name or sys_id>') will work fine in your script include.
code in SI:
if(gs.getUser().isMemberOf('Premium Plus')){
return true;
}
return false;
Client Script ... code in display function...
var groupValue = response.respo ...........;
if(!groupValue){
g_form.removeOption(. ... .. ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 05:29 PM
Can you post your script include and client script code here, I will copy and try in my personal instance.
One quick question instead of checking group. we can check if the user has a role and then perform our action right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 05:59 PM
Hi Srnewbie,
We can check for role if you want to test it out. But the requirements insists we use groups because some users in the same group has different roles and as a result they will not be able to see the category field.
Script Include -
var Helper = Class.create();
Helper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCustomvalue: function() {
var sys_id=this.getParameter('sys_id');
var custom_val;
var val=new GlideRecord('sys_user');
val.addQuery('sys_id',sys_id);
val.query();
if(val.next()){
if(gs.getUser().isMemberOf('GROUP'))
{
return true;
}
return false;
}},
type: 'Helper'
});
Catalog Client Script -
function onLoad() {
var ga = new GlideAjax('Helper');
ga.addParam('sysparm_name', 'getCustomvalue');
ga.addParam('sys_id', g_user.userID);{
ga.getXML(display);
}
function display(response) {
var groupValue = response.responseXML.documentElement.getAttribute("answer");
//alert('here1');
if(!groupValue)
{
//alert('here');
g_form.removeOption('category', 'Internal');
}
}
}
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 06:27 PM
Hi Srnewbie,
I got it working!! All i had to do was take away the "RETURN FALSE" in the script include.
Thank you