Pass work notes from one task to the next HELP

jonsr20
Tera Expert

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();
}

 

1 ACCEPTED SOLUTION

More string manipulation technics.  This should leave just the name and work note, though you might have 2 names for every entry given the first Notes Example above.  If that's still the case and you can't find what is adding the 'System' you can try to add a replace for 'System (Work note)s' before the existing one.  As a bonus, this approach will (theoretically) still work on 2100-01-01.

(function onBefore(current, previous) {
	var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item);
    gr.addInactiveQuery();
    gr.orderByDesc('number');
    gr.query();
    if (gr.next()) {
		var wnArr = [];
		var wn = gr.work_notes.getJournalEntry(-1).split('\n');
		for (var i = 0; i < wn.length; i++) {
			wn[i] = wn[i].replace('(Work notes)', '');
			var index = wn[i].indexOf(' - ');
			if (index > 0) {
				index += 3;
			}
			wnArr.push(wn[i].substring(index));
		}
		current.work_notes = wnArr.join('\n');
    }
})(current, previous);

 

View solution in original post

24 REPLIES 24

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 :(.