Business Rule : SN_Work Notes from RITM to SCTASK
Table: sc_req_item
When: After
(function executeRule(current, previous /*null when async*/) {
var sys_id = current.getUniqueValue();
var scTaskGR = new GlideRecord('sc_task');
scTaskGR.addActiveQuery();
scTaskGR.addQuery('request_item', sys_id);
scTaskGR.query();
if(scTaskGR.hasNext()){
var curWN = current.work_notes.getJournalEntry(1);
while(scTaskGR.next()){
if(scTaskGR.work_notes.getJournalEntry(1) == '' || curWN.indexOf(scTaskGR.work_notes.getJournalEntry(1)) <0){
scTaskGR.work_notes = curWN;
scTaskGR.update();
}
}
}
})(current, previous);
SN_Work Notes from SCTASK to RITM
Table: sc_task
When: After
(function executeRule(current, previous /*null when async*/) {
var ritm = new GlideRecord('sc_req_item');
if(ritm.get(current.request_item)){
var curWN = current.work_notes.getJournalEntry(1);
if(ritm.work_notes.getJournalEntry(1) == '' || curWN.indexOf(ritm.work_notes.getJournalEntry(1)) <0){
ritm.work_notes = curWN;
ritm.update();
}
}
})(current, previous);
How do we sync comments added at the RITM down to associated Catalog tasks? In this video we create 2 business rules (on sc_req_item and sc_task tables, NOT Flow designer for once :)) to synchronise work notes between RITM and Catalogue tasks. We can apply this logic to other situations where have parent and child tasks e.g. Incident and Incident tasks, Change and change tasks (you get the idea). We can if we want apply this not only to work notes but additional comments too!…or both. EDIT: It has been bought to my attention that there are occasions where I put my big mug (face) in the way of the good stuff! (sorry messing with edits)..for those that noticed I apologies and see this link for the code: https://service-nerd.com/2022/10/24/servicenow-sync-work-notes-between-ritm-and-catalog-task-synchronise-parent-and-child-tasks/ Other references if you want to explore and try something different: https://www.servicenow.com/community/developer-forum/sync-ing-ritm-and-sctask-work-notes-additional-comments/m-p/1731613/page/2 https://gist.github.com/jacebenson/4b89d0be8c6cf0460b4c054762e69b76 #servicenerd #servicenow #notFlowDesigner