Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Round robin assigned

Uchel
Tera Contributor

HI All,

 

I want to ask how to create a round-robin type approach (Auto Assignment).

Here's my old script but not working.

Condition:

Uchel_0-1709196120660.png

Script:

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

    var arrayUtil = new global.ArrayUtil();
   
    var assignmentType = '';
    var assignToThisUser = '';
    var matchingRuleFound = false;
    var matchingRuleSysID = '';
  
    var getAssignmentRule = new GlideRecord('u_group_assignment_rule');
    getAssignmentRule.addQuery('u_name', 'CDP_CCR_RR_assign');
    //getAssignmentRule.addQuery('u_name', 'CDP_CCR_Alpha_RR_assign');
    getAssignmentRule.query();
   
    while(getAssignmentRule.next()){
        assignmentType = getAssignmentRule.u_assignment_type;
        matchingRuleSysID = getAssignmentRule.sys_id;
        matchingRuleFound = true;
    }
    if (matchingRuleFound){

        var asgUserList = []; //userlist of assignment group into array
       
        //Need to look up the Group Members
        gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group',current.assignment_group);
        gr.orderBy('user.first_name');
    //  gr.addQuery('u_exclude_assignment','false');
        gr.addQuery('available','true');
        gr.query();
        while (gr.next()){
           
            asgUserList.push(gr.getValue('user'));
        }
       
        if (assignmentType == 'Round Robin'){
           
            var position = 0;
           
            if (getAssignmentRule.u_round_robin_last_assigned == ''){
               
                assignToThisUser = asgUserList[position];
               
            }
            else{
               
                position = arrayUtil.indexOf(asgUserList, getAssignmentRule.u_round_robin_last_assigned); //get the index of the last assigned
                position++;  
               
                if(position < asgUserList.length){

                    assignToThisUser = asgUserList[position];
                }
                else{
                   
                    assignToThisUser = asgUserList[0];
                }
            }
        }
       
        var gr = new GlideRecord('x_amspi_cdp_request');
        gr.addQuery('number',current.number);
        gr.query();
        while(gr.next())
            {
                gr.assigned_to = assignToThisUser;
                gr.update();

            }
       
       
    }
   
})(current, previous);
2 REPLIES 2

Sohail Khilji
Kilo Patron

Hi @Uchel ,

 

Why dont you make sure of Advance work assignment module ? 

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/administer/advanced-work-as...


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Uchel 

 

SN provide the AWA - Advance Work Assignment module, which help you to achieve this without any code. The only configuration is required .

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************