- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 10:38 AM - edited 12-02-2024 12:12 PM
Hello!
We have a requirement where we are wanting all additional comments entered at RITM level to be updated on all associated SCTASKS as an additional comment. In addition, we are needing this same requirement to go the other way so that when an additional comment is entered at the SCTASK level, it adds/updates the additional comment at the RITM level. I will need the complete script for how to accomplish this along with any step-by-step instructions as I have never done this before. I am an admin in our system, but do not have developer/scripting abilities at this time. Appreciate in advance any insight on how to get this completed!
EDIT: I have figured out how to roll comments entered at RITM level to add to SCTASK level, but will need help with the script to update any additional comment entered to SCTASK to update on RITM additional comments.
Here is my script for updating additional comments from RITM to SCTASK, I need help with script for SCTASK>RITM additional comments:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 12:26 PM
If you want to get a little fancier, here's the current iteration of the scripts we have been using to which add the Task/RITM number for reference, prevent recursion, and won't copy duplicates when users repeatedly enter the same comment for whatever reason.
The first rule, on the sc_req_item table after Update when Additional comments changes:
(function executeRule(current, previous /*null when async*/) {
//To Copy the Additional Comments from RITM to SCTASKs
var compare = '';
var ritm_comment2 = '';
var ritm_comment = '';
var task_comment2 = '';
var task_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 task_gr = new GlideRecord('sc_task');
task_gr.addQuery('request_item', current.sys_id);
task_gr.addQuery('active', 'true');
task_gr.query();
while (task_gr.next()) {
task_comment = task_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);
var numberstring = current.number + ' - ';
var regex2= new RegExp(numberstring);
var i2 = task_comment2.search(regex2);
if(i2>=0) {
task_comment2 = task_comment2.substring(i2+numberstring.length, task_comment2.length);
}
} else {
task_comment2 = 'empty';
}
var numberstring2 = task_gr.number + ' - ';
var regex3= new RegExp(numberstring2);
var i3 = ritm_comment2.search(regex3);
if(i3>=0) {
ritm_comment2 = ritm_comment2.substring(i3+numberstring2.length, ritm_comment2.length);
}
compare = ritm_comment2.indexOf(task_comment2);
if (compare != 0) {// if no match found
task_gr.comments = current.number + ' - ' + ritm_comment2.trim();
task_gr.update();
}
}
})(current, previous);
The second rule, on the sc_task table after Update when Additional comments changes:
(function executeRule(current, previous /*null when async*/) {
//to copy the Additional Comments from SCTASK to RITM
var compare = '';
var task_comment2 = '';
var task_comment = '';
var ritm_comment2 = '';
var 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.request_item);
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);
var numberstring = current.number + ' - ';
var regex2= new RegExp(numberstring);
var i2 = ritm_comment2.search(regex2);
if(i2>=0) {
ritm_comment2 = ritm_comment2.substring(i2+numberstring.length, ritm_comment2.length);
}
} else {
ritm_comment2 = 'empty';
}
var numberstring2 = ritm_gr.number + ' - ';
var regex3= new RegExp(numberstring2);
var i3 = task_comment2.search(regex3);
if(i3>=0) {
task_comment2 = task_comment2.substring(i3+numberstring2.length, task_comment2.length);
}
compare = task_comment2.indexOf(ritm_comment2);
if(compare != 0) { // If no exact entire match found
ritm_gr.comments = current.number + ' - ' + task_comment2.trim();
ritm_gr.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 12:26 PM
If you want to get a little fancier, here's the current iteration of the scripts we have been using to which add the Task/RITM number for reference, prevent recursion, and won't copy duplicates when users repeatedly enter the same comment for whatever reason.
The first rule, on the sc_req_item table after Update when Additional comments changes:
(function executeRule(current, previous /*null when async*/) {
//To Copy the Additional Comments from RITM to SCTASKs
var compare = '';
var ritm_comment2 = '';
var ritm_comment = '';
var task_comment2 = '';
var task_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 task_gr = new GlideRecord('sc_task');
task_gr.addQuery('request_item', current.sys_id);
task_gr.addQuery('active', 'true');
task_gr.query();
while (task_gr.next()) {
task_comment = task_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);
var numberstring = current.number + ' - ';
var regex2= new RegExp(numberstring);
var i2 = task_comment2.search(regex2);
if(i2>=0) {
task_comment2 = task_comment2.substring(i2+numberstring.length, task_comment2.length);
}
} else {
task_comment2 = 'empty';
}
var numberstring2 = task_gr.number + ' - ';
var regex3= new RegExp(numberstring2);
var i3 = ritm_comment2.search(regex3);
if(i3>=0) {
ritm_comment2 = ritm_comment2.substring(i3+numberstring2.length, ritm_comment2.length);
}
compare = ritm_comment2.indexOf(task_comment2);
if (compare != 0) {// if no match found
task_gr.comments = current.number + ' - ' + ritm_comment2.trim();
task_gr.update();
}
}
})(current, previous);
The second rule, on the sc_task table after Update when Additional comments changes:
(function executeRule(current, previous /*null when async*/) {
//to copy the Additional Comments from SCTASK to RITM
var compare = '';
var task_comment2 = '';
var task_comment = '';
var ritm_comment2 = '';
var 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.request_item);
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);
var numberstring = current.number + ' - ';
var regex2= new RegExp(numberstring);
var i2 = ritm_comment2.search(regex2);
if(i2>=0) {
ritm_comment2 = ritm_comment2.substring(i2+numberstring.length, ritm_comment2.length);
}
} else {
ritm_comment2 = 'empty';
}
var numberstring2 = ritm_gr.number + ' - ';
var regex3= new RegExp(numberstring2);
var i3 = task_comment2.search(regex3);
if(i3>=0) {
task_comment2 = task_comment2.substring(i3+numberstring2.length, task_comment2.length);
}
compare = task_comment2.indexOf(ritm_comment2);
if(compare != 0) { // If no exact entire match found
ritm_gr.comments = current.number + ' - ' + task_comment2.trim();
ritm_gr.update();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:00 PM
Thank you for your response. These scripts may be overkill for what we are trying to accomplish. Essentially, I just need the script I provided in my initial question modified so any SCTASK entered additional comment rolls up and is added to the RITM additional comments in the same manner I have set with comments rolling from RITM to SCTASK.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:05 PM
See Brad's solution here:
Much simpler than what he proposed above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 01:10 PM
We had to depart from the simple approach once we had task comments updating the RITM and vice-versa as comments were duplicating in a recursive manner.