Comments duplication

Vishal Jawalka1
Tera Expert

I have a business rule that copies additional comments from Req to task and I have another business rule that copies additional comments from task to request, respectively.

Whenever the I am entering comments on Tasks it duplicates as if the other business rule is running and copying the comments thus duplicating it.

 

How to stop this duplication.

 

Please help.

1 ACCEPTED SOLUTION

Vishnu Prasad K
Giga Guru

Hi Vishal,

 

Use gs.getSession().isInteractive()

View solution in original post

11 REPLIES 11

Hi Vishal,

 

Use the below script

 

(function executeRule(current, previous /*null when async*/) {

var newComment = current.comments.getJournalEntry(1);
var commentAlreadyAdded = false;

// Look to see if the comment has been added to tasks yet
var grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.getValue("sys_id"));
grTask.addQuery('active', true);
grTask.query();
while (grTask.next()) {
var taskComments = grTask.comments.getJournalEntry(-1);
taskComments = taskComments.split("\n\n");

// Check each to see if the newComment has already been added
for (var i = 0; i < taskComments.length; i++) {
if (taskComments[i].trim() != '' && newComment.includes(taskComments[i]) == true) {
commentAlreadyAdded = true;
return;
}
}
}

// If newComment has not been added to any tasks, add it and update
if (!commentAlreadyAdded) {
grTask = new GlideRecord('sc_task');
grTask.addQuery('request_item', current.getValue("sys_id"));
grTask.addQuery('active', true);
grTask.query();
while (grTask.next()) {
grTask.comments = newComment;
grTask.update();
}
}

})(current, previous);

Community Alums
Not applicable

This worked for me!!! Thank you so much!!