- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:10 PM
Hi,
We have requirement that
When we updated comments in SCTASK , the same should be reflect in RITM also .
How to implement this requirement.
Please provide me implementation steps
@Saurav11 @kamlesh kjmar @Community Alums @Gunjan Kiratkar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 08:31 PM
Please do the below:-
Create a after insert/update BR on sc_req_item table as below:-
Write the below code in the 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);
Then Wriye an after insert/update BR on sc_task table as below.:-
I think you already have created the BR for sc_task table with the above condition. So just update the code to below:-
(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 my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:22 PM
Hi, Please refer solution at the URL below
https://www.servicenow.com/community/developer-forum/update-work-notes-and-comments-between-records/...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:28 PM
Hello,
Please write an After Insert/Update business rule that runs on SC Task table with condition comments changes
(function executeRule(current, previous /*null when async*/ ) {
var ritmis= new GlideRecord('sc_req_item');
ritmis.addQuery('sys_id', current.request_item);
ritmis.query();
if (ritmis.next()) {
ritmis.comments= "Catalog Task Comments for " + current.number + " : " + current.comments;
ritmis.update();
}
})(current, previous);
Please check below articles for more information:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:39 PM
Go to Business rule and create a new one with the below screenshot condition:-
And then copy paste the script which I had mentioned earlier in the script part:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 08:06 PM