Cancel HR Task if the subject person of the parent case is not a manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 11:40 PM
Hi There,
I have a lifecycle case that has a task that gets created. I need to cancel that HR task if the subject person for the Parent case is not a manager. How can I do this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 12:01 AM
@Simran321 You need to write an onBefore insert business rule on your HR Task table as follows.
Here is the script for your reference.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var glideUser = new GlideAggregate('sys_user');
glideUser.addQuery('manager', gs.getUserID());
glideUser.addAggregate('COUNT');
glideUser.query();
var managerCount = 0;
if (glideUser.next()) {
managerCount = glideUser.getAggregate('COUNT');
}
if (managerCount == 0) {
current.setValue('state', '7'); //set the state to cancelled.
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 09:28 AM
@Sandeep Rajput - Thanks for your response. The HR Task is the child task of Lifecycle case. I need to find id parent case subject person is the manager. So cannot use gs.getuserID()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 08:52 PM
Here is the updated script for the subject person.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var glideUser = new GlideAggregate('sys_user');
glideUser.addQuery('manager', current.parent.subject_person);
glideUser.addAggregate('COUNT');
glideUser.query();
var managerCount = 0;
if (glideUser.next()) {
managerCount = glideUser.getAggregate('COUNT');
}
if (managerCount == 0) {
current.setValue('state', '7'); //set the state to cancelled.
}
})(current, previous);