Work notes only copied to one task, not all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
42m ago
Hi
My business rule isn’t working as expected. What am I missing? When I add work notes to Task 1, they only update Task 2, but Task 3 doesn’t get any of the notes. It seems to copy notes from Task 1 to Task 2, but Task 3 remains unchanged
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11m ago
Hi @CarolMa6,
I would review the trigger conditions...
it's set "Work notes changes" + "State is Closed complete".
I guess it means that you have a record in closed complete state and after you add WN to it, so it's trigger after that. Adjust current or add a new condition line "State changes to CC".
Make the condition as simple as possible for quick debugging - make it to be always trigerable (e.g. WN changes), then add a WN and you will see if something is happening or not:
- If not,
- it's not the condition being wrong, but the code.
- If yes,
- it was the condition what was not ok and needs some tweaks...
This reply is 100 % GlideFather and 0 % AI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5m ago
Hello @CarolMa6
Use your condition properly and use async BR instead of after BR.
(function executeRule(current, previous /*null when async*/) {
// 1. Get the latest entry
var latestEntry = current.work_notes.getJournalEntry(1);
// Safety check: ensure we actually have text
if (!latestEntry) return;
// 2. Clean the "Double Header" (Optional but recommended)
// Splits the entry by new lines and removes the first line (the timestamp/name header)
var cleanEntry = latestEntry;
var entryParts = latestEntry.split('\n');
if (entryParts.length > 1) {
// Rejoin everything after the first line
cleanEntry = entryParts.slice(1).join('\n');
}
// 3. Query Sibling Tasks
var grTask = new GlideRecord("sc_task");
grTask.addQuery("request_item", current.request_item);
grTask.addQuery("sys_id", "!=", current.sys_id); // Use sys_id for safer exclusion than number
grTask.addActiveQuery(); // Usually we only want to update active tasks
grTask.query();
while (grTask.next()) {
// 4. Apply the cleaned note
// We prepend a small tag so people know where this note came from
grTask.work_notes = "[Copied from " + current.number + "] \n" + cleanEntry;
// 5. CRITICAL: Stop Recursion
// This prevents the other tasks from firing their own rules back at us
grTask.setWorkflow(false);
// 6. Optional: Keep the "Updated" timestamp fresh
// setWorkflow(false) stops the 'sys_updated_on' from changing.
// If you want to show it was updated, you sometimes have to force it,
// but usually, silence is preferred for synchronization.
grTask.update();
}
})(current, previous);
