Comment
Pascal Pailloc1
Tera Explorer

Hello,

Thanks for your post!

We noticed a few issues with the Business Rule. Thanks to Lmouity1, hereโ€™s a suggested fix:

(function executeRule(current, previous /*null when async*/) {
     var array = new sn_task_plan.TaskPlanExecutionService().findMatchingTaskPlanTemplate(current);
    var latestRecord = null;
    var latestDate = null;
    for (var i = 0; i < array.length; i++) {
        var currentRecord = array[i];
        var currentDate = new GlideDateTime(currentRecord.sysupdatedon);
        if (latestDate === null || currentDate.getNumericValue() > latestDate.getNumericValue()) {
            latestDate = currentDate;
            latestRecord = currentRecord;
        }
    }
    new sn_task_plan.TaskPlanExecutionService().applyTaskTemplate(latestRecord.sys_id, current);
})(current, previous);

Let us know if it works for you or if you need further clarification