File tree Expand file tree Collapse file tree 1 file changed +26
-10
lines changed
Server-Side Components/Business Rules/Add HR task for HR case Expand file tree Collapse file tree 1 file changed +26
-10
lines changed Original file line number Diff line number Diff line change 1- // Business Rule: ' After' Insert on 'sn_hr_core_case'
1+ // Business Rule: After Insert on 'sn_hr_core_case'
22( function executeRule ( current , previous /*null when async*/ ) {
33
4- if ( current . priority == "1" && current . subject_person . getValue ( 'VIP' ) == 'true' ) {
5- var newTask = new GlideRecord ( 'sn_hr_core_task' ) ;
6- newTask . initialize ( ) ;
7- newTask . short_description = 'Priority VIP HR task for - ' + current . number ;
8- newTask . assigned_to = current . assigned_to ;
9- newTask . parent = current . sys_id ;
10- newTask . insert ( ) ;
11-
12- gs . addInfoMessage ( 'A related HR task has been created for this HR case.' ) ;
4+ // Check if priority is high and subject person is a VIP
5+ const isHighPriority = current . priority == '1' ;
6+ const isVIP = current . subject_person . getValue ( 'VIP' ) === 'true' ;
7+
8+ if ( isHighPriority && isVIP ) {
9+ try {
10+ const task = new GlideRecord ( 'sn_hr_core_task' ) ;
11+ task . initialize ( ) ;
12+
13+ task . short_description = `Priority VIP HR task for - ${ current . number } ` ;
14+ task . assigned_to = current . assigned_to ;
15+ task . parent = current . sys_id ;
16+
17+ const taskSysId = task . insert ( ) ;
18+
19+ if ( taskSysId ) {
20+ gs . addInfoMessage ( '✅ A related HR task has been successfully created for this VIP HR case.' ) ;
21+ } else {
22+ gs . addErrorMessage ( '⚠️ Failed to create HR task for VIP case.' ) ;
23+ }
24+
25+ } catch ( err ) {
26+ gs . error ( 'Error while creating VIP HR Task: ' + err . message ) ;
27+ }
1328 }
1429
1530} ) ( current , previous ) ;
31+
You can’t perform that action at this time.
0 commit comments