How to skip a lifecycle activity set based on the state of an activty in a previous activity set

denisdoucet
Tera Guru

Hello,

I'm developing a Lifecycle Event with multiple activity sets.
The business has a requirement where they want to have 2 paths (Happy and Unhappy paths)
As an example, if the task in Activity Set A is set to Close Complete, choose happy path and go to Activity Set B.
If the task is set to Close Incomplete, chose the unhappy path and skip Activity Set B and C and go to Activity Set D.
I've been playing around with the Advanced Trigger Type on the activity set, but I can't see to come up with the write script to make it work.

 

Any assistance with the script, or alternate solutions would be greatly appreciated.

 

(function executeRule(current, previous /*null when async*/) {
try {
// Define the sys_id of the previous activity set
var previousActivitySetSysId = 'my_activity_set_sys_id';//I have my actual sys_id when I run it

// Get the HR Case associated with the current activity set
var hrCase = new GlideRecord('sn_hr_core_case');
if (hrCase.get(current.parent)) {
// Get all tasks associated with the HR Case
var hrTasks = new GlideRecord('sn_hr_core_task');
hrTasks.addQuery('parent', hrCase.sys_id);
hrTasks.query();

while (hrTasks.next()) {
// Check if the task is part of the previous activity set
if (hrTasks.activity_set == previousActivitySetSysId) {
// Check the state of the task
if (hrTasks.state == '3') {
// If the task is complete, trigger the current activity set
hrTriggerUtil.triggerActivitySet(current.sys_id);
} else {
// If the task is not complete, do not trigger the current activity set
return;
}
}
}
}
} catch (e) {
gs.error('Error in advanced trigger type script: ' + e.message);
}
})(current, previous);
0 REPLIES 0