How to create business rule .When ever incident is created it should assign to the user who has less numbers tickets and should assign to same group.

shiva narayana
Kilo Contributor

How to  create business rule .When ever  new incident is created It should assign Assignment group to particular group and it should assigned to the group member who is having less number of tickets 

NEED SCRIPT 

For example;

In hardware group there are 3 members A,B,C

A user has 2 tickets 

B user has 4 tickets 

c user has 7 tickets 

It should assigned to A user when incident is created 

Thanks 

shiva

10 REPLIES 10

Martin Ivanov
Giga Sage
Giga Sage

is the Assignment group assigned by an agent or it should be assigned automatically as well?


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Hello 

it should Assign automatically while creating incident 

Thanks 

shiva

Here is a first-call solution that comes to my mind. Please keep in mind that it may be a bit heavy from performance point of view.

Please mark CORRECT AND HELPFUL if appropriate. Thanks!

find_real_file.pngfind_real_file.png


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Hello 

var groupName = 'CAB Approval';
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));
}
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);
}
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); } }

var userID = members[index];


var user = new GlideRecord('sys_user');
if (user.get(userID)) {
gs.log('Name: ' + user.name);
}
var a= new GlideRecord('incident');
a.addQuery('state',1);


a.query();
while(a.next())
{
if(a.assigned_to==''){
current.assigned_to=userID;
current.update();

}
}

 

Can you please help me .

When ever new incident is created  it should assign to cab approval group

In that group it should  assign to the user who has  less tickets

 

Thanks 

shiva