How to write a BR that copies close notes from task to request?

Jay Jay
Giga Expert

I have had some trouble making an BR that copies close notes from SC Task to request table (preferly it only adds info and not delete if field allready has txt in it )... Problem is i dont see what the error is...

 

Please check screenshots

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

You should be able to do this with a single 'After' 'Update' business rule on the 'sc_task' table.  The business rule should run when the Close notes field changes and the Close notes field is not empty.  Here is the script...

(function executeRule(current, previous /*null when async*/) {
	// Query for the Request parent
	var req = new GlideRecord('sc_request');
	req.addQuery('sys_id', current.request_item.request);
	req.query();
	if (req.next()) {
		// Add current close notes to request close notes
		req.close_notes = req.close_notes + '\n' + 'Close notes added from ' + current.number + ':\n' + current.close_notes + '\n';
		req.update();
	}
})(current, previous);

View solution in original post

12 REPLIES 12

Mark Stanger
Giga Sage

You should be able to do this with a single 'After' 'Update' business rule on the 'sc_task' table.  The business rule should run when the Close notes field changes and the Close notes field is not empty.  Here is the script...

(function executeRule(current, previous /*null when async*/) {
	// Query for the Request parent
	var req = new GlideRecord('sc_request');
	req.addQuery('sys_id', current.request_item.request);
	req.query();
	if (req.next()) {
		// Add current close notes to request close notes
		req.close_notes = req.close_notes + '\n' + 'Close notes added from ' + current.number + ':\n' + current.close_notes + '\n';
		req.update();
	}
})(current, previous);

@Mark Stanger

 

Thanks for attempt... But it still doesnt copy anything. Not to RITM / REQ. How do i figure out whats wrong when i turn on debug i get this " business rule21:32:39.975: Global ==> 'Copy closenotes Task - RITM - REQ' on sc_task:SCTASK0022936" So it is like it runs the rule but nothing really happens....

 

Any suggestions ? 

 

I also tried to change condition to run only when close notes changes result = nothing

Nevermind got your rule to work Mark. THANX everyone!