How to copy whole work note from task to incident

lucky24
Tera Contributor

Hi Team,

 

I am converting task to incident in which I am copying work notes from task to incident

I have written ss rule on incident with below code

 

var sTask = new GlideRecord("sc_task");
if (sTask.get(current.parent)) {
current.work_notes = sTask.work_notes.getJournalEntry(1);
current.update();
}

But I am getting only current work notes I want whole worknotes  I tried also with = "current.work_notes = sTask.work_notes" but this is not working.

 

Please help me here how can I copying whole worknotes

1 ACCEPTED SOLUTION
3 REPLIES 3

Niklas Peterson
Mega Sage
Mega Sage

Hi @lucky24 

 

Use getJournalEntry(-1) instead of getJournalEntry(1).

https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideElementScope...

Regards,
Niklas

Thanks Niklas

 

Above suggestion is working for me

Riya Verma
Kilo Sage
Kilo Sage

Hi @lucky24 ,

 

Hope you are doing great.

 

Below is reference script to copy entire worknotes:

 

// Retrieve the parent task
var sTask = new GlideRecord("sc_task");
if (sTask.get(current.parent)) {
    // Copy all work notes from the task to the incident
    var workNotes = '';
    var journal = new GlideRecord("sys_journal_field");
    journal.addQuery("element_id", sTask.sys_id);
    journal.addQuery("element", "comments");
    journal.query();
    while (journal.next()) {
        workNotes += journal.value + '\n';
    }
    
    // Set the copied work notes on the incident
    current.work_notes = workNotes;
    current.update();
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma