Make Variables visible for certain group members

Rowella Montell
Tera Contributor

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!

1 ACCEPTED SOLUTION

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:

find_real_file.png

 

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

find_real_file.png

 

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:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

19 REPLIES 19

Hi Sohail,

 

Thank you for your response.

Does it mean that it would be better to just use client script and create a script include to show/hide the variables for a certain group members in my catalog item in Service Portal instead of just using a script function in the catalog UI Policy?

Yes make use of client script instead of UI policy as the data is been checked from server side.

you can use the below 2 method to do it :

1. Client script with GlideAjax

2. Client script with scratchpad variable 

 

Both works, as your requirement is simple which does not have complex condition check you can make use of option 2  > i.e. Client script with scratchpad variable to check if user belongs to group.

 

 

Check this :

https://community.servicenow.com/community?id=community_question&sys_id=c97a07e9db5cdbc01dcaf3231f961990

 

 

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

LinkedIn - Lets Connect

var UserGroup = Class.create();
UserGroup.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
result: function(){

var user = this.getParameter('sys_parm_user');
var grUserGroup = new GlideRecord('sys_user_group'); 
grUserGroup.addQuery('user', user); 
grUserGroup.addQuery('group', '45c5f542db9bb0d0791cdae2f39619dd');
grUserGroup.query();
	
if(grUserGroup.hasNext()){
return true;
}
else{
return false;
}

	type: 'UserGroup';
   
}});

Hi @sohail 

 

I tried using your code above and just changed some var names but I'm getting an error: 

find_real_file.png

 

Below is the code I have in Script Include:

 

Hi 

 

use this code, just tested it and it worked fine :

var UserGroup = Class.create();
UserGroup.prototype = {
	initialize: function() {
	},
	result: function(){
		
var user1 = this.getParameter('sys_parm_user');
		
var grUserGroup = new GlideRecord('sys_user_grmember'); 
grUserGroup.addQuery('user',user1 ); 
grUserGroup.addQuery('group', '45c5f542db9bb0d0791cdae2f39619dd');
grUserGroup.query();
	
if(grUserGroup.hasNext()){	
return 'true';
}		
else{
return false;
}	
		
	},
	
	type: 'UserGroup'
};

 

 

 

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

LinkedIn - Lets Connect

I hope the answer helps, Kindly Mark  Correct if applicable., So that others get benefited in future for similar issues...


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect