Sync'ing RITM and SCTASK work notes \ additional comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2020 03:16 PM
Hello all,
Currently we are attempting to synchronize the additional comments and work notes between RITM and its associated TASKs (and vise versa). Essentially, if a comment or work note is made on a SCTASK, it needs to copy that to the RITMs comments or work notes (or both and again, vise versa)
Below is what we have,
the RITM Business Rule:
(function executeRule(current, previous /*null when async*/ ) {
var taskGR = new GlideRecord('sc_task');
taskGR.addEncodedQuery('request_item=' + current.getUniqueValue());
taskGR.query();
//gs.info("BR is active");
while (taskGR.next()) {
if ((taskGR.work_notes.getJournalEntry(1) != current.work_notes.getJournalEntry(1)) && (taskGR.comments.getJournalEntry(1) != current.comments.getJournalEntry(1))) {
taskGR.comments = current.comments;
taskGR.work_notes = current.work_notes;
taskGR.update();
}
}
})(current, previous);
the SCTASK Business Rule:
(function executeRule(current, previous /*null when async*/ ) {
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('sys_id=' + current.request_item.sys_id);
ritmGR.query();
//gs.info("BR is active");
while (ritmGR.next()) {
if ((ritmGR.work_notes.getJournalEntry(1) != current.work_notes.getJournalEntry(1)) && (ritmGR.comments.getJournalEntry(1) != current.comments.getJournalEntry(1))) {
ritmGR.comments = current.comments;
ritmGR.work_notes = current.work_notes;
ritmGR.update();
}
}
})(current, previous);
We wanted to avoid an infinite loop situation so we have the if statements there to prevent that, however, for example, if I make a comment on the task, it will update the ritm, which then updates the task. This leaves the task with a duplicate comment, and I am wondering if anyone has a solution for this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2020 03:20 PM
while we do push comments from SCTask to RITM (so Requester gets notified), we push Comments from RITM to Worknotes on SCTask but we check if the updater is the same person assigned to the SCtask. If they are, we don't send the comments to SCtask. Here's the script we use to check:
ar ritmupdater = gs.getUserID();
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query();
while(gr.next()){
//if RITM is updated by SCTASK assigned to, don't push comments to work notes
if (gr.assigned_to != ritmupdater)
gr.work_notes = current.comments;
gr.update();
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2021 07:46 AM
Hi Dom,
We had the same requirement couple of weeks back. I have gone through many community posts and answers on this requirement and finally with some tweaks in the code it worked like a charm.
Please make sure that the Business Rules on both sc_req_item and sc_task table is working on 'After' the update(do not use insert).Below is the code and conditions worked avoiding the infinite loop.
the RITM Business Rule:
When:After - Update
Additional Comments - Changes
Script:
(function executeRule(current, previous /*null when async*/) {
updateTasks();
function updateTasks() {
var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
ritm_comment =current.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = ritm_comment.search(regex);
if (i>0)
{
ritm_comment2 = ritm_comment.substring(i+1, ritm_comment.length);
}
var ritm_gr = new GlideRecord('sc_task');
ritm_gr.addQuery('request_item', current.sys_id);
ritm_gr.query();
if(ritm_gr.next())
{
task_comment =ritm_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = task_comment.search(regex);
if(i1 > 0)
{
task_comment2 = task_comment.substring(i1+1, task_comment.length);
}
compare = ritm_comment2.indexOf(task_comment2);
if(compare == -1) // If No match found
{
ritm_gr.comments = ritm_comment2.trim();
ritm_gr.update();
}
}
}
})(current, previous);
the SCTASK Business Rule:
When: After - Update
Additional Comments - Changes
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
task_comment =current.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = task_comment.search(regex);
if (i>0)
{
task_comment2 = task_comment.substring(i+1, task_comment.length);
}
var ritm_gr = new GlideRecord('sc_req_item');
ritm_gr.addQuery('sys_id', current.parent);
ritm_gr.query();
if(ritm_gr.next())
{
ritm_comment =ritm_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = ritm_comment.search(regex);
if(i1 > 0)
{
ritm_comment2 = ritm_comment.substring(i1+1, ritm_comment.length);
}
compare = task_comment2.indexOf(ritm_comment2);
if(compare == -1) // If No match found
{
ritm_gr.comments = task_comment2.trim();
ritm_gr.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2021 07:47 AM
Please mark this as helpful if this works for you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2021 07:49 AM
Hi Dom,
We had the same requirement couple of weeks back. I have gone through many community posts and answers on this requirement and finally with some tweaks in the code it worked like a charm.
Please make sure that the Business Rules on both sc_req_item and sc_task table is working on 'After' the update(do not use insert).Below is the code and conditions worked avoiding the infinite loop.
the RITM Business Rule:
When:After - Update
Additional Comments - Changes
Script:
(function executeRule(current, previous /*null when async*/) {
updateTasks();
function updateTasks() {
var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
ritm_comment =current.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = ritm_comment.search(regex);
if (i>0)
{
ritm_comment2 = ritm_comment.substring(i+1, ritm_comment.length);
}
var ritm_gr = new GlideRecord('sc_task');
ritm_gr.addQuery('request_item', current.sys_id);
ritm_gr.query();
if(ritm_gr.next())
{
task_comment =ritm_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = task_comment.search(regex);
if(i1 > 0)
{
task_comment2 = task_comment.substring(i1+1, task_comment.length);
}
compare = ritm_comment2.indexOf(task_comment2);
if(compare == -1) // If No match found
{
ritm_gr.comments = ritm_comment2.trim();
ritm_gr.update();
}
}
}
})(current, previous);
the SCTASK Business Rule:
When: After - Update
Additional Comments - Changes
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var compare,task_comment2,task_comment,ritm_comment2,ritm_comment;
task_comment =current.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var regex= new RegExp('\n');
var i = task_comment.search(regex);
if (i>0)
{
task_comment2 = task_comment.substring(i+1, task_comment.length);
}
var ritm_gr = new GlideRecord('sc_req_item');
ritm_gr.addQuery('sys_id', current.parent);
ritm_gr.query();
if(ritm_gr.next())
{
ritm_comment =ritm_gr.comments.getJournalEntry(1);
//Remove timestamp and name from additional comment
var i1 = ritm_comment.search(regex);
if(i1 > 0)
{
ritm_comment2 = ritm_comment.substring(i1+1, ritm_comment.length);
}
compare = task_comment2.indexOf(ritm_comment2);
if(compare == -1) // If No match found
{
ritm_gr.comments = task_comment2.trim();
ritm_gr.update();
}
}
})(current, previous);
Please mark this as helpful if this works for you