Assign INC based on less inc assigned to team member

Pawan Kumar Rai
Tera Contributor

If user update "Assignment group" field and save, ServiceNow should automatically pick one member of the group with minimum incident ticket assigned and set the user in "assigned to" field

 

Please show step wise.

6 REPLIES 6

Hemanth M1
Giga Sage
Giga Sage

Hi @Pawan Kumar Rai ,

 

Please explore "Advanced Work Assignment" >> https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/advanced-work-assignment... 

 

If you try to achieve through custom logics and scripts , we may end up in many challenges 

ex:

1)what if Many users has same number tickets assigned to them

2)Avaibility,Skills?? to attend the ticket

3)Maintenance of your logic??

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

In Advanced work assignment there is no table field to specify on which table the rule should apply.

I'm using custom CSM application and looking for auto assign user with least cases assigned.

could you please assist

"Advanced Work Assignment"  does not have specify table on which it should apply.

Im using custom csm application . please assist on auto assign least assigned user

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Pawan Kumar Rai 

If you are looking out for script, You can have before BR of your choice & code will be as below:

Condition: current.assignment_group.changes() && current.assignment_group.previous != current.assignment_group

Script in BR:

 

(function executeRule(current, previous /*null when async*/) {
    var assignmentGroup = current.assignment_group;

    var grMembers = new GlideAggregate('incident');
    grMembers.addQuery('assignment_group', assignmentGroup);
    grMembers.addAggregate('COUNT', 'assigned_to');
    grMembers.groupBy('assigned_to');
    grMembers.orderByAggregate('COUNT', 'assigned_to');
    grMembers.query();

    var membersWithMinLength = [];
    var minCount = -1;
    
    while (grMembers.next()) {
        var count = grMembers.getAggregate('COUNT', 'assigned_to');
        if (minCount === -1 || count < minCount) {
            minCount = count;
            membersWithMinLength = [grMembers.assigned_to.toString()];
        } else if (count === minCount) {
            membersWithMinLength.push(grMembers.assigned_to.toString());
        } else {
            break;
        }
    }

    if (membersWithMinLength.length > 0) {
        var randomIndex = Math.floor(Math.random() * membersWithMinLength.length);
        current.assigned_to = membersWithMinLength[randomIndex];
    }
})(current, previous);



Please mark as Accepted Solution & helpful if you get it 🙂

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)