Pass work notes from one task to the next HELP

jonsr20
Tera Guru

Hey everyone,

 

I have need for comments from task to follow over to the next task in workflows. I have searched and found a post that said it has a solution but it is not working for me, wondering if anyone has any advice or what I am doing wrong. I created a business rule with 'after' update and conditions are work notes changes and state is closed complete. Below is the script but it is not working for me. Any advice would be really helpful! Here is the script what am I doing wrong?

 

task.work_notes=pullComments();
function pullComments(){
var comments=[];
var gr= new GlideRecord("sc_task");
gr.addQuery("request_item",current.getValue("sys_id"));

//order by sys_created_on and limit to one record
gr.orderByDesc('sys_created_on');
gr.setLimit(1);

gr.query();
while(gr.next()){
task.short_description = gr.short_description;
task.description = gr.description;

var wn = gr.work_notes.getJournalEntry(-1);
var regex= new RegExp('\n');
var a = wn.search(regex);

wn = wn.substring(a+1, wn.length);
comments.push(wn);

}
gs.log("From workflow final return "+comments.join());
return comments.join();
}

 

Vrushali  Kolte
Mega Sage

@jonsr20 

 

Please try to update the script in BR as below

 

 

 

 if (current.work_notes.changes() && current.state == 'closed_complete') {
        
var workNotes = current.work_notes.getJournalEntry(-1);
var sc_task = new GlideRecord("sc_task");
sc_task.addQuery('request_item', current.request_item);
sc_task.addEncodedQuery('sys_id!=' + current.sys_id);
sc_task.query();
while(sc_task.next()){
sc_task.worknotes = workNotes;
sc_task.update();
}
}
      

 

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Still nothing, do I keep the conditions on here even though you inserted that if statement? Attached a picture of conditions and this is how the script appears. Your help is much appreciated 🙂

 

(function executeRule(current, previous /*null when async*/) {

        
 if (current.work_notes.changes() && current.state == 'closed_complete') {
        
var workNotes = current.work_notes.getJournalEntry(-1);
var sc_task = new GlideRecord("sc_task");
sc_task.addQuery('request_item', current.request_item);
sc_task.addEncodedQuery('sys_id!=' + current.sys_id);
sc_task.query();
while(sc_task.next()){
sc_task.worknotes = workNotes;
sc_task.update();
}
}

})(current, previous);

 

@jonsr20 

 

Can you remove the "if" statement and try once, I mean remove the condition

 

Thanks!

Tried that and still nothing :(.