File tree Expand file tree Collapse file tree
Server-Side Components/Business Rules/Auto Assign a CR Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments