
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 03:11 AM
Hi All,
I was given a task to create a new catalog item and one of the requirements is that some variable fields should be only visible to a certain group members. I'm trying to create a script in the Catalog UI Policy to do this, what I need to do is to get servicenow read if the current logged in user is a member of a certain group and if he/she is then some variable fields should be visible to them. Can anyone help as to how I can achieve this? I'm still new to this so I'm not really sure how this should work.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2021 11:10 PM
Okay this is what it should have returned to you.
Now can you make sure you have given the correct variable names in your script. It should be the backend Name of the variable.
Can you share screenshot of your variable form which shows the name to make sure that has been entered is correct.
Like for example in my case, my current logged in user is part of two groups as shown below:
Now in my script I am checking if User is part of "Team Development Code Reviewers" queue then I am hiding my Variables 1 and Variables 2
This hides both my Variables on the form. For reference I have attached my Variable form screenshot as well below to make sure the name added to your script is the name highlighted:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 03:22 AM
Hi Rowella
can you share the script you configured?
You need to use glideajax for this, In your script Include use below logic in your method to get logged in user is member of group or not.
var member = gs.getUser().isMemberOf('GroupName/Group Sysid');
//member will store true/false.
return member;
Glide Ajax- https://docs.servicenow.com/bundle/rome-application-development/page/script/ajax/topic/p_AJAX.html#d...
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 06:12 PM
Hi Rohila,
I'm pretty sure the code I have earlier is really not the way to do it, see below:
I tried the code you have in the script for Catalog UI Policy script but when I check in he service portal I'm getting an error message: There is a JavaScript error in your browser console.
I've saved the setting to run for mobile/serviceportal as we need this for SP:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 06:42 PM
Hello Rowella
Try using Business Rule
I have found a thread, which might be helpful for you
Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat
https://www.linkedin.com/in/gauravshirsat/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2021 06:44 PM
Hi
Use GlideAjax for this as below,
Catalog Client Script:
var ga = new GlideAjax('checkuserpartofgroup');
ga.addParm('syyparm_name' 'checkgroup');
ga.addParm('sys_parm_user', gs.getUser());
ga.getXML(result);
function result (response){
var answer = response.responseXML.documentElement.getAttribute("answer");
//your client logic here to show/hide field
}
Script include:
result: function(){
var user = this.getParameter('sys_parm_user');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user);
gr.addQuery('group', '<sys_id_group>');
gr.query();
if(gr.hasNext()){
return true;
else{
return false;
}
}
I hope the answer helps, Kindly Mark ✅ Correct or ???? Helpful if applicable., So that others get benefited in future for similar issues...
Thanks,
MF Sohail Khilji.
LinkedIn > https://www.linkedin.com/in/mf-sohail-khilji/
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....