- 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 08:09 PM - edited 11-29-2022 08:15 PM
Hello.
I have updated the script. Please use the below script in the business rule it will work. I have tested it on my PDI.
(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.getJournalEntry(1);
ritmis.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 08:18 PM
I have one more request ,
If i have update comments in RITM also the same should refelect in SCTASK also
How to do that
- 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:35 PM
Hi @nameisnani ,
You will need to create a After Update business rule on the SC Task table, with condition as Additional comments changes
var ritm_gr = new GlideRecord('sc_req_item');
ritm_gr.addQuery('sys_id', current.getValue("request_item"));
ritm_gr.query();
if(ritm_gr.next()){
ritm_comment =current.comments.getJournalEntry(1);
ritm_gr.update();
}
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 08:18 PM