copy comments from problem_task to problem and vice versa

tghadage124
Tera Contributor

Hi guys ,

i have requirement related to copy of work notes from problem to problem_task and vice versa , 

 

for copying from problem to problem_task its working here is the code : 

its after update BR on problem table : 

 

var problemTask = new GlideRecord('problem_task');
problemTask.addQuery('problem', current.sys_id);  
problemTask.query();

if (problemTask.next()) {
    var workNote = current.work_notes.getJournalEntry(1);
    problemTask.work_notes = workNote;
    problemTask.update();
----------------------------------------------------------------------------------------------------------------------------
 
but to copy from problem_task to problem its not working here is the code :
 
its after update BR on problem table :
 
var problemTask = new GlideRecord('problem_task');
problemTask.addQuery('problem', current.sys_id);
problemTask.query();

while (problemTask.next()) {
    var workNote = problemTask.work_notes.getJournalEntry(1);
   // if (workNote) {
        current.work_notes = current.work_notes + '\n' + workNote;
        gs.info('Copied work note to parent problem: ' + workNote);
    //}
}

current.update(); 
 
----------------------------------------------------------------------------------------------------
can you please help me on this ? 
 
thanks!! 
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@tghadage124 

the 2nd BR should be this

var problemRec = new GlideRecord('problem');
problemRec.addQuery('sys_id', current.problem);
problemRec.query();
if(problemRec.next()) {
        problemRec.work_notes = current.work_notes.getJournalEntry(1);
problemRec.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

hi @Ankur Bawiskar , 

its still not working actually. 

 

thanks!!

hi @Ankur Bawiskar , 

 

its working now but getting like this : 

image (10).png

its getting repeated comments can you please help !

@tghadage124 

check this link and it will tell solution on how to handle recursion

Sync'ing RITM and SCTASK work notes \ additional comments 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader