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

Sumanth16
Kilo Patron

Hi @jonsr20 , 

 

Please try below script:

 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addQuery('sys_id','!=',current.sys_id);
gr.orderByDesc('number');

gr.query();

while(gr.next())

{
gr.work_notes = current.work_notes;
gr.update();
}

 

Note: use After Business rule and set the condition worknotes changes

 

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

 

Thanks & Regards,

Sumanth Meda

Still not working :(.

jonsr20
Tera Expert

Bump,

 

Any assistance on this would be much appreciated!

Brad Bowman
Kilo Patron
Kilo Patron

This script looks like it's written for a Catalog Task activity on a workflow as 'task.' is otherwise undefined.  If you are running a workflow with sequential, not parallel Catalog Tasks, that's probably a better/easier place to do this.  If you want this to apply to all Catalog Tasks in all Catalog Items then a Business Rule would be better, but the trigger should be before Insert, if your Catalog Tasks are not created until the previous one is closed.

Yes, I would like it to apply to all catalog tasks. I tried making the business rule before insert, but the work notes still do not carry over to the next task. Is the syntax of the script no good for a business rule? Forgive my ignorance 😅.