assign a incident automatically to a user in group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 04:40 AM
Hi,
I have a requirement, when inbound email action is triggered and created a incident in servicenow, automatically it has to assign incident to a person in the group based upon his workload. For example if 2 persons are in a group and one person is working on 2 incidents and another person don't have any incidents to work, then automatically it has to assign incident to this person.
Can anyone let me, how can achieve this.
Thanks
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 04:52 AM
In inbound mail action you can create a glide query in script and assign it to user as per this use case.
Thanks
Akhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 05:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 05:27 AM
I love coding challenges
In my instance I have the following open Incident by User. You want the code to tell you the person with the lowest ticket count. So that's Beth Anglin (the are only 4 memebers - nobody has 0)
var groupName = 'Service Desk';
// Get a list of members for this group
var members = [];
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('user.active', true);
gm.addQuery('group.name', groupName);
gm.query();
while (gm.next()) {
members.push(String(gm.user));
}
// Get a list of their open ticket counts
var counts = [], agg, count;
for (var i = 0; i < members.length; i++) {
count = 0;
agg = new GlideAggregate('incident');
agg.addActiveQuery();
agg.addQuery('assignment_group.name', groupName);
agg.addQuery('assigned_to', members[i]);
agg.addAggregate('COUNT');
agg.query();
if (agg.next())
count = agg.getAggregate('COUNT');
counts.push(count);
}
// find the minimum count and store its index
// we cannot use .sort().shift() or we won't know where to look in the members array
var min = counts[0];
var index = 0;
for (var j = 1; j < counts.length; j++) {
if (counts[j] < min) {
min = parseInt(counts[j]);
index = parseInt(j);
}
}
// get the member with the lowest count
var userID = members[index];
// Log their name to verify
var user = new GlideRecord('sys_user');
if (user.get(userID)) {
gs.log('Name: ' + user.name);
}
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2016 05:48 AM
Hi Geoffrey,
Thanks for your reply and but actual requirement is not to count the users with lowest count. Requirement is a incident will be created using inbound email action and service-now has to automatically assign the incident based upon person with the lowest ticket count.
Hope you are clear I believe.
