reference qualifier in catalog item

xlarge74
Tera Expert

good morning,

 

we have in our incident form two fields (assigned group and assigned to) where the system filters only matching records if one field is filled with data. this works vice versa.

 

i would like to use this now in an catalog item where i need exactly the same  fileds (user and group) to be filtered.

we have three tables -->  sys_user sys_user_group and sys_user_grmember,

 do you have any hints for me to lets say copy the behaviour of the incident fileds 😄

 

kind regards 

Oliver

3 ACCEPTED SOLUTIONS

Hi @xlarge74 ,

 

Similar question i have answered please check the below article,

You can do the same for catalog item just change the field names accordingly,

https://www.servicenow.com/community/itsm-forum/need-to-have-assignment-group-only-show-groups-that-... 

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,

Swathi Sarang

View solution in original post

Hi @xlarge74 ,

try below script include and use on groups reference qualifier

var getUserGroups = Class.create();
getUserGroups.prototype = {
initialize: function() {},
getGroups: function(userId) {
if (userId) {
var groupsArr = [];
var grUsrMem = new GlideRecord('sys_user_grmember');
grUsrMem.addEncodedQuery('user=' + userId);
grUsrMem.query();

while (grUsrMem.next()) {
groupsArr.push(grUsrMem.group.getValue());
}
return 'sys_idIN' + groupsArr;
}
},

type: 'getUserGroups'
};
 
use below reference qualifier on the users variables
javascript: new getUserGroups().getGroups(current.variables.users);
If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

Good morning, i found out how to do it 🙂

i just filtered in the group table and copied the query and added the "group." to access the attributes of the group object. 

Maybe i can help somebody else with this finding 😄

 

 

 

var tfGetUserGroups = Class.create();
tfGetUserGroups.prototype = {
initialize: function() {},
getGroups: function(userId) {
if (userId) {
var groupsArr = [];
var grUsrMem = new GlideRecord('sys_user_grmember');
grUsrMem.addEncodedQuery('user=' + userId);
grUsrMem.addEncodedQuery("group.type=1cb8ab9bff500200158bffffffffff62^group.active=true");
grUsrMem.query();
var arr =[];
while (grUsrMem.next()) {
groupsArr.push(grUsrMem.group.getValue());
}


return 'sys_idIN' + groupsArr;
}
},

type: 'tfGetUserGroups'
};

 

 

 

The javascript for the reference qualifier (group): 

 

 

javascript: new tfGetUserGroups().getGroups(current.variables.u_durchfuehrende_person); 

 

 

BTW: The "javascript:" doesnt work in my environment. I had to switch it back to "javascript:

 

 Here is what it does:

I have a user field (u_durchfuehrende_person) which is entered by the user.

The next filed is the group field. There should only groups be shown, which are assigned to the user. Second step is to show just the groups with the type 'itil' and active=true. This encoded query was done via the group table filter. The query was copied and put in the addEncoded query in my script. To access the attributes of the group i just added group. in front of the attributes (as seen in the code example). et voila 😄 I´m so happy now thanks to swathisarang98 and Pavankumar_1 who led me to the solution.

 

kind regards

Oliver

View solution in original post

15 REPLIES 15

Slava Savitsky
Giga Sage

Check the reference qualifiers of the fields in the Incident table and apply the same reference qualifiers to the corresponding variables in your catalog item.

good morning 

i tried, but the mechanics between incident and catalog item are slightly different 😞

 

kind regards oliver

sunil_m_l10
Tera Expert

Hi @xlarge74 

Add below code in Reference Qualifier

 

 

javascript; new scriptIncludeName().getUsers(current.variables.assignment_group);

 

 
Use below function in script include

 

getUsers : function(grGroup) {
		
		var arr =[];
		var grUsers = new GlideRecord('sys_user_grmember');
		grUsers.addEncodedQuery('group='+grGroup);
		grUsers.query();

		while(grUsers.next())
		{
			arr.push(grUsers.user.getValue());
		}
                return 'sys_idIN'+arr;
	},


Note: Replace scriptIncludeName with your Script Include Name

 

dear sunil,

i´m sorry for my late reply.

 

if im searching for the groups the user is attached to i have to rewrite this right?

 

for example:

first field im entering the user

second filed should only show the groups with type 'itil'  from this user

 

kind regards

oliver