The CreatorCon Call for Content is officially open! Get started here.

Request item record work notes & additional comments write to new Task record after approval

MMT3
Tera Contributor

When a sc_request_item record is created there is an approval required before the sc_task record is created.   If the approval record is approved and the sc_task is created how do I get the works notes and additional comments from the sc_request_item record to appear in the work notes and additional comments of the sc_task record?  The work notes and additional comments were added to the sc_request_item record before the sc_task was created because the approval step.

 

I created a business rule (listed below) with the following script but I don't know how to modify so that the sc_request_item record pushes existing work notes and additional comments to the newly created sc_task record.  The works notes and additional comments are made before the sc_task record even exists. 

 

function onBefore(current, previous) {
   //This function will be automatically called when this rule is processed.
   var gr = new GlideRecord('sc_task');
    gr.get(current.request_item);
    gr.comments = current.comments;
    gr.work_notes = current.work_notes;
    gr.update();
}
 
Thank you in advance for your help.
2 REPLIES 2

Azem
Tera Guru

Hello, you need to relate the 2 tables when performing queries. Please try script below

Table: Requested Item

When to run: Before Insert, Update

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

	var gr = new GlideRecord('sc_task');
	gr.addQuery('request_item', current.sys_id);
    gr.query();
	if (gr.next()){
    gr.comments = current.comments;
    gr.work_notes = current.work_notes;
    gr.update();
	}

})(current, previous);

 

fmelard
Tera Expert

Hi,

You may try to change the order or when the BR is executed, in your case it could be after, even asynch (there is like 5sec delay as this is queued for later execution).

The sc_task will be created after the "BR before" with an order below 1000, you can also try on before with an order 1100 but this may be too short.

this is more or less the order in the system: BR before (order <1000) / WF / BR before (order >1000) / BR after / BR asynch.

 

More details here:

https://docs.servicenow.com/bundle/utah-build-workflows/page/administer/service-administration/refer...