Copying additional comments from SCTASK to RITM and RITM to all SCTASKs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 09:21 AM
I have a project to add additional comments from a SCTASK to the RITM and also add the additional comments from a RITM to all the SCTASKs under that RITM. I'm testing this on my personal dev instance.
I have created these two business rules:
Add Comments from RITM to all SCTASKs
Add Comments from SCTASK to RITM
I have tested them individually and they work as far as pushing the additional comment from the RITM to all the SCTASKs and also from the SCTASK to the RITM. Originally I only had one of them active during my testing. But when I activated both of them, then it adds two comments to the RITM or SCTASK which I don't want to happen.
I'm hoping someone knows what I need to do so the business rules won't execute so the RITM or SCTASK gets two comments. I only want the comment added one time when pushing it to the other item. I have tried multiple codes but still don't have it working.
When I add an additional comment to the SCTASK, I want it added to the SCTASK and to the RITM only once. When I add an additional comment to the RITM, I want it added to the RITM and to all the SCTASKs under that RITM only once in all of them. Apparently the business rules execute a couple times which has caused them to add the comment twice to the RITM or SCTASK. I still haven't figured out how to only add the comment once. I'm really hoping someone has an answer for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 09:26 AM
Do you actually want to copy them... or do you want to make their content visible on related records?
i.e.: when someone looks at the RITM, they can see all entries in the related SCTASKs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 09:29 AM
Yes, I want the additional comment from the SCTASK added to the RITM. I want the additional comment from the RITM added to all the SCTASKs under that RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 09:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 09:40 AM
This code worked fine when I only had one of them active. But when I made them both active then I got duplicate comments in the RITM and SCTASK.
Here is the code I have tried for "Add Comment from RITM to all SCTASKs". I have tried sctask.setWorkflow(false) but it didn't stop the duplicate comments.
(function executeRule(current, previous /*null when async*/) {
var comments = current.comments;
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item.number', current.number);
sctask.query();
var ritmComments = current.comments.getJournalEntry(1);
//sctask.setWorkflow(false);
while (sctask.next()) {
var sctaskComments = sctask.comments.getJournalEntry(1);
if (ritmComments.indexOf(sctaskComments) < 0) {
//sctask.setWorkflow(false);
sctask.comments = comments;
sctask.update();
//sctask.setWorkflow(false);
}
}
})(current, previous);
Here is the code I have tried for "Add Comment from SCTASK to RITM". I have tried ritm.setWorkflow(false) but it didn't stop the duplicate comments.
(function executeRule(current, previous /*null when async*/) {
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.request_item);
//ritm.setWorkflow(false);
var sctaskComments = current.comments.getJournalEntry(1);
var ritmComments = ritm.comments.getJournalEntry(1);
if (sctaskComments.indexOf(ritmComments) < 0) {
var comments = current.comments;
//ritm.setWorkflow(false);
ritm.comments = comments;
ritm.update();
}
//ritm.setWorkflow(false);
})(current, previous);