Skip to content

Commit e7b798d

Browse files
author
SWETHA R
authored
Update Add HR Task for VIP HR Case.js
1 parent 9a8fe4f commit e7b798d

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
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+

0 commit comments

Comments
 (0)