Need to display only one group users in assigned to variable which is referencing to sys_user table

sumanth1
Tera Contributor

In one catalog item I have only assigned to variable and no assignment group variable .Assigned to variable is referencing to sys_user table .I have to display only one group members in assigned to variable.can any one provide the script to achieve this.

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @sumanth1 ,

 

You just need to write a small script in the advance reference qualifier, no need of script include, paste this code in the advance reference qualifier:

javascript: var grpGR = new GlideRecord('sys_user_grmember');
grpGR.addQuery('group', " <your group's sys_id>");
grpGR.query();
var users='';
while(grpGR.next()){
users+=grpGR.user.sys_id + ",";
}
"sys_idIN" + users;

 

I used "ITSM-App Dev" group for testing:

KaranChhabra6_1-1682449162625.png

KaranChhabra6_2-1682449222361.png

 

If my answer has helped with your question, please mark it as helpful and accepted solution.

 

Thanks,
Karan

 

 

 

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@sumanth1 Please use the following steps to implement this requirement.

1. Create a Script Include to provide filter for the Assigned_to reference field.

Here is how you will configure the script include.

Screenshot 2023-04-25 at 11.24.26 PM.png

We are going to use getUserFromGroup function from this script include to filter assigned_to list based on the group.

Here is the code for script include.

var MyUtilsV2 = Class.create();
MyUtilsV2.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
	myFunc:function(){
		return 'hello';
	},
    
	getUsersFromGroup: function(groupName){
		if(groupName){
			var glideGrMember = new GlideRecord('sys_user_grmember');
			glideGrMember.addEncodedQuery('group.name='+groupName);
			glideGrMember.query();
			var userArray = [];
			while(glideGrMember.next()){
				userArray.push(glideGrMember.getValue('user'));
			}

			return 'sys_idIN'+userArray.toString();
		}
	},
    
    type: 'MyUtilsV2'
});

Now time to configure your variable on the catalog item.

This is how you should do it.

Screenshot 2023-04-25 at 11.24.53 PM.png

 Here is the code for advanced qualifier.

javascript&colon; new global.MyUtilsV2().getUsersFromGroup('ITSM App-Dev');

Here we are calling method getUsersFromGroup and passing the group name 'ITSM App-Dev'. You can change the group name on the basis of your current implementation.

 

This is how this functionality works.

Screenshot 2023-04-25 at 11.22.54 PM.pngScreenshot 2023-04-25 at 11.23.03 PM.png

The reference field only allows users to choose from the members of 'ITSM-App Dev' group.

 

Hope this helps.

 

Karan Chhabra6
Mega Sage
Mega Sage

Hi @sumanth1 ,

 

You just need to write a small script in the advance reference qualifier, no need of script include, paste this code in the advance reference qualifier:

javascript&colon; var grpGR = new GlideRecord('sys_user_grmember');
grpGR.addQuery('group', " <your group's sys_id>");
grpGR.query();
var users='';
while(grpGR.next()){
users+=grpGR.user.sys_id + ",";
}
"sys_idIN" + users;

 

I used "ITSM-App Dev" group for testing:

KaranChhabra6_1-1682449162625.png

KaranChhabra6_2-1682449222361.png

 

If my answer has helped with your question, please mark it as helpful and accepted solution.

 

Thanks,
Karan

 

 

 

Thanks Karan it worked for me.

Hi karan can you help me with the similar one i need to display the user where the user id contains "adm"