Comments to be added when record is approved

Pranavi2
Tera Contributor

Hi,

How to write a script so that when an approver approves the request, the comments or worknotes of the table should be populated with the info that "The request has been approved by xyz user"?

In the change request table, we have a field 'test' that identifies that the change has been created from Jira and for these particular tickets, when approver approves, the comments or work notes has to be populated. How to achieve this? 

1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage
Mega Sage

Hi @Pranavi2 ,

 

Write an on after update BR on approval table with below mentioned condition and script:

 

kamleshkjmar_1-1667534267736.png

 

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

	// Add your code here
	if(current.sysapproval.u_test == "put_your_value") //put your logic how to identify, chg created from jira
	{
		var chg = current.sysapproval.getRefRecord();
		chg.comments = "The request has been approved by "+ current.getDisplayValue("approver") +" user";
		chg.update();
	}

})(current, previous);

 

 

kamleshkjmar_0-1667534996526.png

 

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

View solution in original post

4 REPLIES 4

kamlesh kjmar
Mega Sage
Mega Sage

Hi @Pranavi2 ,

 

Write an on after update BR on approval table with below mentioned condition and script:

 

kamleshkjmar_1-1667534267736.png

 

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

	// Add your code here
	if(current.sysapproval.u_test == "put_your_value") //put your logic how to identify, chg created from jira
	{
		var chg = current.sysapproval.getRefRecord();
		chg.comments = "The request has been approved by "+ current.getDisplayValue("approver") +" user";
		chg.update();
	}

})(current, previous);

 

 

kamleshkjmar_0-1667534996526.png

 

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

Hi @kamlesh kjmar ,

Thank you this worked. 

I wrote an after update BR on change_Request table with the below code. It didn't work . Can you please tell what's wrong here?

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

	// Add your code here
	var ap_gr = new GlideRecord("sysapproval_approver");
	ap_gr.addQuery("sysapproval",current.sys_id);
	ap_gr.query();
	
	while(ap_gr.next()){
		if (ap_gr.state.changesTo('approved')){
			current.comments = "test comment";
		}
	}

})(current, previous);

 

 

Hi @Pranavi2 ,

 

Is this another use case ? changesTo() method works with current record i.e. record on which update operation is happeing. Here you are trying this method with GlideRecord which I don't think will work.

 

Could you please elaborate your need.

 

Regards,

Kamlesh

Hi @kamlesh kjmar ,

It is for the same question I posted, before your reply I just tried the one I pasted and it didn't work for me, so I just wanted to check with you what's wrong in the code I pasted. Now I have changed my code with the one you provided, your code is working fine and solved my requirement.

Thank you