diff --git a/Server-Side Components/Business Rules/Copy Worknotes/read.md b/Server-Side Components/Business Rules/Copy Worknotes/read.md new file mode 100644 index 0000000000..e70d452e20 --- /dev/null +++ b/Server-Side Components/Business Rules/Copy Worknotes/read.md @@ -0,0 +1,4 @@ +Copy work notes to parent +Checks if work notes have changed in the current record. +If yes, it copies the latest journal entry to the parent’s work notes. +Sets the updated flag to true. diff --git a/Server-Side Components/Business Rules/Copy Worknotes/script.js b/Server-Side Components/Business Rules/Copy Worknotes/script.js new file mode 100644 index 0000000000..8868fb7a05 --- /dev/null +++ b/Server-Side Components/Business Rules/Copy Worknotes/script.js @@ -0,0 +1,22 @@ +/Copy work notes to parent +/* Checks if work notes have changed in the current record. +If yes, it copies the latest journal entry to the parent’s work notes. +Sets the updated flag to true.*// +(function executeRule(current, previous) { + if (!current.parent) return; + + var parent = current.parent.getRefRecord(); + if (!parent.isValidRecord()) return; + + var updated = false; + + + if (current.work_notes.changes()) { + parent.work_notes = current.work_notes.getJournalEntry(1); + updated = true; + } + + if (updated) { + parent.update(); + } +})(current, previous);