Need to copy comments from approver table to ritm

Akshata3
Giga Contributor

Hi Team,

I need to copy comments from Approval(sysapproval_approver) to RITM, how to achieve it?

Regards,

Akshata Patil

1 ACCEPTED SOLUTION

Dan H
Tera Guru

Hi,

Try this:

//Name: Copy comments from Approval to RITM
//Table:  sysapproval_approver
//Advanced:  true
//When:  Before Update; Additional Comments <changes>
//Condition:  current.comments.changes() && current.comments.indexOf('Comment added from:') < 0;
//  Note that the condition prevents the note from copying multiple times.

//Script:

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

	if(current.comments.nil()){
		return;
	}	

	else {

		var gr = new GlideRecord('sc_req_item'); 
		gr.addQuery('sys_id',current.document_id);
		gr.query();
		while(gr.next()){
			gr.comments = "Comment added from: " + current.number + " | " +current.request_item.cat_item.name + "\n >>>  " +current.comments;
			gr.update();
		}
	}
})(current, previous);

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

View solution in original post

4 REPLIES 4

Vasantharajan N
Giga Sage
Giga Sage

Create business rule on sysapproval_approver table to get the comments and record sys_id using which you can add the comments to sc_req_item table. 


Thanks & Regards,
Vasanth

Dan H
Tera Guru

Hi,

Try this:

//Name: Copy comments from Approval to RITM
//Table:  sysapproval_approver
//Advanced:  true
//When:  Before Update; Additional Comments <changes>
//Condition:  current.comments.changes() && current.comments.indexOf('Comment added from:') < 0;
//  Note that the condition prevents the note from copying multiple times.

//Script:

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

	if(current.comments.nil()){
		return;
	}	

	else {

		var gr = new GlideRecord('sc_req_item'); 
		gr.addQuery('sys_id',current.document_id);
		gr.query();
		while(gr.next()){
			gr.comments = "Comment added from: " + current.number + " | " +current.request_item.cat_item.name + "\n >>>  " +current.comments;
			gr.update();
		}
	}
})(current, previous);

 

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Akshata3
Giga Contributor

Thank you it worked

kmannem
Tera Contributor

Hi Dan,

 

I tried writing this business rule but this does not seem to work. Any suggestions here?

 

Thanks,

Kushala