diff --git a/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/README.md b/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/README.md new file mode 100644 index 0000000000..6688d341be --- /dev/null +++ b/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/README.md @@ -0,0 +1,20 @@ +This is an Async Update Business rule written on the Requested Item table. +This code works as a comment synchronization mechanism. + +What the code does: +-Comment is added to the parent record(which in this case is a Requested Item) +-Creates an HTML link to the parent record using its number. +-Queries and finds all active SCTASKs associated with the Reuqested item. +-Loops through each SCTASK, adds the copied comment along with a link to the Requested Item. + +Let's explain with an example: + +RITM: RITM001001 +Task 1: SCTASK001001 +Task 2: SCTASK001002 +-User adds new comment into the RITM: 'This is a test comment.' +-Record link is created and stored inside a clickable RITM number. +-The RITM comment is updated on both the SCTASKs with the comment looking like: + + Updated comments on: [RITM001001] + This is a test comment. diff --git a/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/synccommentfromritmtotask.js b/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/synccommentfromritmtotask.js new file mode 100644 index 0000000000..032d37e74b --- /dev/null +++ b/Server-Side Components/Business Rules/Synchronize RITM comments to Active tasks/synccommentfromritmtotask.js @@ -0,0 +1,14 @@ +(function executeRule(current, previous /*null when async*/ ) { + + var ritmLink = '[code]' + current.number.toString() + '[/code]'; + + var scTask = new GlideRecord('sc_task'); + scTask.addQuery('request_item', current.sys_id); + scTask.addActiveQuery(); + scTask.query(); + while (scTask.next()) { + scTask.comments = 'Updated comments on: ' + ritmLink + '\n' + current.comments.getJournalEntry(1); + scTask.update(); + } + +})(current, previous);