sometimes you only know the user and not the assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 10:49 AM
Hi Team,
sometimes you only know the user and not the assignment group. How can you then get the group suggestions in order to set the correct assignment group in the form? (Incident, Problem, Change)
BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:49 AM
If you're asking how to filter the list of Assignment groups to only those that the Assigned to is a member of, you need to change the Dictionary Override reference qualifier for each table (Incident, Problem, Change) to something that looks like this:
Where ReferenceQualifierHelper is the name of a Client callable Script Include, and backfillAssignmentGroup is the name of a function in that SI. The SI would look something like this to show all support type groups if Assigned to is empty, otherwise only the support type groups that the Assigned to is a member of:
var ReferenceQualifierHelper = Class.create();
ReferenceQualifierHelper.prototype = {
backfillAssignmentGroup: function(assigned_to) {
var groupTypes = new GlideRecord('sys_user_group_type');
groupTypes.addQuery('name', 'itil');
groupTypes.query();
if (groupTypes.next())
//we have a group type of support/itil so continue
//save the Support Type sys_id
var support = groupTypes.getValue("sys_id");
var assigneeGroupsQualifier = '';
//var assignee = current.assigned_to;
var groupTypeQuery = 'typeLIKE' + support + '^active=true^EQ';
//return if the assigned_to value is empty (this causes all groups to be returned)
gs.log('Groups= ' + support);
if (!assigned_to)
return groupTypeQuery;
//sys_user_grmember has the user to group relationship
var grAssigneeGroups = new GlideRecord('sys_user_grmember');
grAssigneeGroups.addQuery('user', assigned_to);
grAssigneeGroups.query();
while (grAssigneeGroups.next()) {
//now check each group to see if it is an assignment group
var groups = new GlideRecord('sys_user_group');
//look for the group
groups.addQuery('sys_id', grAssigneeGroups.group);
//look for only active records
groups.addActiveQuery();
groups.query();
while (groups.next()) {
//found a match
//Check if this group's type is Support
//If not found, it will return -1 so we don't want to include it
if (groups.type.indexOf(support) != -1) {
if (assigneeGroupsQualifier.length > 0) {
//build a comma separated string of groups if there is more than one
assigneeGroupsQualifier += (',' + grAssigneeGroups.group.toString());
} else {
assigneeGroupsQualifier = grAssigneeGroups.group.toString();
}
} //end if indexOf
} //end if groups.next
} //end while
// return Groups where assigned to is in those groups we use IN for lists
gs.log('DP: RefQual = ' + assigneeGroupsQualifier);
return 'sys_idIN' + assigneeGroupsQualifier;
},
type: 'ReferenceQualifierHelper'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:58 AM
Hi, it is quite common to see a reference qualifier that looks up the sys_user_grmember records for the assignee of the task and only returns the sys_id's of groups that the user is a member of. the query could also utilize other fields from any of the records involved to allow for better management of the available groups ie group.type, group.active etc. The easiest way to deliver this would be via a script-include function,, code that you can test in a PDI background window.
//for PDI testing in background window
var current = new GlideRecord('incident');
current.get('d71f7935c0a8016700802b64c67c11c6');
var myAssignee = current.assigned_to;
//create a function based on this code and pass in the task assignee IE current.assigned_to as parameter myAssignee;
//array for the results
var groupList = [];
//query for matched records
var groupCheck = new GlideRecord('sys_user_grmember');
groupCheck.addQuery('group.active', true);
groupCheck.addQuery('user', myAssignee);
groupCheck.query();
while(groupCheck.next()) {
//push the groups sys_id's to a string
groupList.push(groupCheck.group.sys_id);
}
gs.info(groupList.toString());
//return the array as a string
//So you have a comma seperated list if sys_id's that can be used in an advanced refqualifier 'IN" query, something like this
//'sys_idIN' + new yourScriptIncludenane().yourFunctionName(current.assigned_to);