Auto Assign To Based On Group Members
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:21 PM
In ServiceNow, when someone updates the assignment group for an incident ticket, the system should automatically check if that new assignment group has only one member. If there's only one person in the group, their name should be automatically filled into the "Assigned To" field without the need for additional clicks. This streamlines the process, avoiding the manual selection of the assigned person when the assignment group has a single member. Can anyone help me achieve this?
In the first picture attached, the assignment group "Tablet" only has one person in it and I would like when anyone selects an assignment group with a maximum of one person, it automatically fills that person in to the assigned to box but I can't seem to make it work.
The second picture is what settings I have so far. I just need the code to make this all work. Also, I don't know if it has to be a business rule or not but please give me any suggestions on how I can get this to work. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:37 PM
Your Business Rule should be on OnBefore BR. And the in the BR script, you can add below script.
var userGrMember = new GlideRecord('sys_user_grmember');
userGrMember.addQuery('group', current.assignment_group);
userGrMember.addQuery('user.active', true);
userGrMember.query();
if (userGrMember.getRowCount() == 1){
current.assigned_to = userGrMember.next().user;
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 08:23 PM
Hi @msekla
If you'd like the Assigned to auto-populated after Assignment group changes on form, you can implement an OnChange Client Script with an Ajax call. Sample below
#Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('CLIncidentUtilsAJAX');
ga.addParam('sysparm_name', 'getGroupMember');
ga.addParam('sysparm_group_id', newValue);
ga.getXMLAnswer(function(answer){
var members = answer.split(',');
if(members.length == 1){
g_form.setValue('assigned_to', members[0]);
}
});
}
#Script Include (Client Callable checked)
var CLIncidentUtilsAJAX = Class.create();
CLIncidentUtilsAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupMember: function(){
var groupID = this.getParameter('sysparm_group_id');
var members = [];
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', groupID);
grMember.addQuery('user.active', true);
grMember.query();
while(grMember.next()){
members.push(grMember.getValue('user'));
}
return members.join(',');
},
type: 'CLIncidentUtilsAJAX'
});
If you would like to implement a Business Rule, you can define an OnBefore Business Rule with the Assignment group changes condition and sample advanced script below.
var gaMember = new GlideAggregate('sys_user_grmember');
gaMember.addQuery('group', current.getValue('assignment_group'));
gaMember.addQuery('user.active', true);
gaMember.orderBy('user');
gaMember.groupBy('group');
gaMember.addAggregate('COUNT', 'user');
gaMember.query();
if(gaMember.next()){
var count = gaMember.getAggregate('COUNT', 'user');
if(count == 1){
current.setValue('assigned_to', gaMember.user);
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 09:00 PM
Greetings.
Yes you can do this via BR and AJAX call.
But - Why don't you add Advanced Assignment Rule in your option list?
That is quite simple to configure and get it live.