- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 02:43 AM
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.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 04:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 06:33 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 04:50 AM
This worked for me!!! Thank you so much!!