The CreatorCon Call for Content is officially open! Get started here.

Hide service portal category item based on user group

thiraj
Tera Contributor

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)

find_real_file.png

This is the CATALOG CLIENT SCRIPT

find_real_file.png

All help is appreciated.

Thank you Team

1 ACCEPTED SOLUTION

Gurpreet07
Mega Sage

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(. ... .. ;


}


View solution in original post

7 REPLIES 7

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?


thiraj
Tera Contributor

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


thiraj
Tera Contributor

Hi Srnewbie,



I got it working!! All i had to do was take away the "RETURN FALSE" in the script include.



Thank you