Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Catalog item: How to get value of one variable based on another variable

vidhya_mouli
Tera Sage

I have catalog item with 2 variables employee and group. Employee is a reference field based on sys_user table. Group is also a reference field based on sys_user_group table. When I choose the value of the employee, i want to display only those group to which this employee belongs. How to do this?

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage

Hi @vidhya_mouli ,

 

You can achieve this by creating script include and calling it through reference qualifier,

 

You can add reference qualifier in Group field like below,

swathisarang98_0-1709289672970.png

 

 

 

javascript: new getuserGroup().getgroupDeatils(current.variables.user)

 

 

 

Script Include:

swathisarang98_0-1709290298002.png

 

 

 

var getuserGroup = Class.create();
getuserGroup.prototype = {
    initialize: function() {
    },

	getgroupDeatils: function(user){
		var sysId = user;
		var groupName = new GlideRecord('sys_user_grmember');
		groupName.addQuery('user',sysId);
		groupName.query();
		var arr =[];
		while(groupName.next()){
			arr.push(groupName.group.toString());
		}
		gs.info('line number 15 ' + arr);
		// gs.info('line number 16 ' + arr.toString());
		// gs.info('line number 17 ' + arr.getDisplayValue());
			return 'sys_idIN'+ arr;
	},

    type: 'getuserGroup'
};

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

16 REPLIES 16

Dr Atul G- LNG
Tera Patron

Hi @vidhya_mouli 

 

https://www.servicenow.com/community/itom-forum/show-group-members-for-a-selected-user-on-a-catalog-...

 

https://www.servicenow.com/community/itsm-forum/get-all-groups-user-is-a-member-of-based-off-of-a-ca...

 

These will be helpful.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

swathisarang98
Giga Sage

Hi @vidhya_mouli ,

 

You can achieve this by creating script include and calling it through reference qualifier,

 

You can add reference qualifier in Group field like below,

swathisarang98_0-1709289672970.png

 

 

 

javascript: new getuserGroup().getgroupDeatils(current.variables.user)

 

 

 

Script Include:

swathisarang98_0-1709290298002.png

 

 

 

var getuserGroup = Class.create();
getuserGroup.prototype = {
    initialize: function() {
    },

	getgroupDeatils: function(user){
		var sysId = user;
		var groupName = new GlideRecord('sys_user_grmember');
		groupName.addQuery('user',sysId);
		groupName.query();
		var arr =[];
		while(groupName.next()){
			arr.push(groupName.group.toString());
		}
		gs.info('line number 15 ' + arr);
		// gs.info('line number 16 ' + arr.toString());
		// gs.info('line number 17 ' + arr.getDisplayValue());
			return 'sys_idIN'+ arr;
	},

    type: 'getuserGroup'
};

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

I used exactly your code but struggling to get the values.

vidhya_mouli_0-1709296619994.png

 

On group field:

javascript: new getuserGroup().getgroupDeatils(current.variables.employee_name)

 

vidhya_mouli_1-1709296674762.png

 

Script Include:

var getuserGroup = Class.create();
getuserGroup.prototype = {
    initialize: function() {
    },

	getgroupDeatils: function(user){
		var sysId = user;
		var groupName = new GlideRecord('sys_user_grmember');
		groupName.addQuery('user',sysId);
		groupName.query();
		var arr =[];
		while(groupName.next()){
			arr.push(groupName.group.toString());
		}
		gs.info('line number 15 ' + arr);
		return 'sys_idIN'+ arr;
	},

    type: 'getuserGroup'
};