Comment
Pascal Pailloc1
Tera Explorer
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
โ11-18-2025
02:44 PM
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