We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to auto populate 'assigned to' field based on the assignment group on incident table

sunil7
Giga Expert

Hi everyone,

I have a requirement to auto populate 'assigned to' field based on Assignment group(Ex. Licence Varification) on incident table. How to achieve this please help?

1 ACCEPTED SOLUTION

Hi,

For random assignment you can use this

Before Insert BR

Script:

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

    // Add your code here

var arr = [];

var member = new GlideRecord('sys_user_grmember');
member.addQuery('group.name','SAM-LicenseVerification');
member.query();
while(member.next()){
arr.push(member.getValue('user'));
}

var randomNumber = Math.floor(Math.random() * Math.floor(4));
current.assigned_to = arr[randomNumber];

})(current, previous);

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Hi,

For random assignment you can use this

Before Insert BR

Script:

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

    // Add your code here

var arr = [];

var member = new GlideRecord('sys_user_grmember');
member.addQuery('group.name','SAM-LicenseVerification');
member.query();
while(member.next()){
arr.push(member.getValue('user'));
}

var randomNumber = Math.floor(Math.random() * Math.floor(4));
current.assigned_to = arr[randomNumber];

})(current, previous);

Regards
Ankur

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