Incident should auto-assign based on the assignment group

Lakshmi53
Tera Contributor

Hi All,

I have a requirement based on user country incident should auto-assign. suppose for india if i have 4 groups based on weight and order ticket need to routing. 

Lakshmi53_0-1742360360153.png

through script 1) it should be assign to 8900 group and then 123 group. after that software and hardware both weight are same at that time it need to assign based on order. 

2) based on weight tickets should assign. if weight is 5 only 5 tickets should assign for s/h remaining should be assign other groups. same as 8900 it should assign 50 tickets

how can i achieve this using business rule.

 

3 REPLIES 3

GopikaP
Mega Sage

Hi @Lakshmi53 , Try this script in business rule - 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var count;
    var inc = new GlideAggregate('incident');
    inc.addAggregate('COUNT');
    inc.groupBy('assignment_group');
    inc.addQuery('assignment_group', 'IN', '553032e853165110b846ddeeff7b12aa,019ad92ec7230010393d265c95c260dd,8a4dde73c6112278017a6a4baf547aa7,8a5055c9c61122780043563ef53438e3');
    inc.query();
    while (inc.next()) {
        var getName = inc.getDisplayValue('assignment_group');
        if (getName == '8900') {
            count = inc.getAggregate('COUNT');
            if (count < 50)
                current.setValue('assignment_group', '553032e853165110b846ddeeff7b12aa');
        } else if (getName == '123') {
            count = inc.getAggregate('COUNT');
            if (count < 40)
                current.setValue('assignment_group', '019ad92ec7230010393d265c95c260dd');

        } else if (getName == 'Software') {
            count = inc.getAggregate('COUNT');
            if (count < 5)
                current.setValue('assignment_group', '8a4dde73c6112278017a6a4baf547aa7');

        } else if (getName == 'Hardware') {
            count = inc.getAggregate('COUNT');
            if (count < 5)
                current.setValue('assignment_group', '8a5055c9c61122780043563ef53438e3');

        }
		current.update();
		current.setWorkflow(false);
    }

})(current, previous);

Ankur Bawiskar
Tera Patron
Tera Patron

@Lakshmi53 

where are you storing this data? in some custom table?

are you saying the country for the caller?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

it's custom table and written below script but not working 

 

 var candidateGroups = new Set();
            var groupGRCountry = new GlideRecord('u_info');
            groupGRCountry.addQuery('u_country', location);
            groupGRCountry.orderBy('u_order');
            groupGRCountry.query();

            while (groupGRCountry.next()) {
                var group = groupGRCountry.getValue('assignment_group');
                if (!candidateGroups.has(group)) {
                    candidateGroups.add(group);
                    gs.info('Added Group (Country Match): ' + group);
                }
            }

            // Convert Set to an array and assign the first available group
           
            var groupList = Array.from(candidateGroups);
            if (groupList.length > 0) {
                current.assignment_group = groupList[0];
                gs.info('Assigned Group from Candidate List: ' + groupList[0]);
            }