Skip to content

Commit ec905bd

Browse files
authored
Create autoAssignCR.js
1 parent cdbafd1 commit ec905bd

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Table: Change Request.
2+
//Condition: Assignment Group changes AND Assigned To is not empty
3+
//When to run: After Update
4+
(function executeRule(current, previous /*null when async*/ ) {
5+
var groupSysId = 'b85d44954a3623120004689b2d5dd60a'; //sys_id of a current assignment group
6+
var array = [];
7+
// Fetch active users in the group
8+
var membersGR = new GlideRecord('sys_user_grmember');
9+
membersGR.addQuery('group', groupSysId);
10+
membersGR.addQuery('user.active', true);
11+
membersGR.query();
12+
var userList = [];
13+
while (membersGR.next()) {
14+
userList.push(membersGR.user.toString());
15+
}
16+
// Round-robin tracking via sys_properties
17+
var propName = 'round_robin.lastUser.' + groupSysId; // Name of the system property that stores the Assigned To value
18+
var lastUser = gs.getProperty(propName, ''); // Value of the system property that stores the previous Assigned To value
19+
var nextUserIndex = 0;
20+
if (lastUser) {
21+
var lastIndex = userList.indexOf(lastUser);
22+
nextUserIndex = (lastIndex + 1) % userList.length;
23+
}
24+
var nextUser = userList[nextUserIndex];
25+
gs.setProperty(propName, nextUser); //Setting the new value for the system property.
26+
current.assigned_to = nextUser;
27+
current.update();
28+
29+
})(current, previous);

0 commit comments

Comments
 (0)