How to copy a field changes on Approval table into a case table work notes when a case is approved ?

Nagurbee1
Tera Contributor

Hello Everyone

I am trying to update a case record work notes with approver name who has approved / rejected a case.

When a case is rejected, rejection comments needs to added in the work notes of a case.

Could any one please help me to achieve it ? (please refer attached screenshot)

 

 

Thanks in advance

Nagurbi

2 ACCEPTED SOLUTIONS

here is a sample, you can add more conditions and refine it as needed

 

AnuragTripathi_2-1729863955518.png

 

 

AnuragTripathi_0-1729863883654.png

 

 

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

	var grec = new GlideRecord("change_request");
	grec.addQuery("sys_id", current.sysapproval);
	grec.query();
	if (grec.next()) {
	   grec.work_notes = 'Action by = '+current.approver.getDisplayValue() ;
	   grec.update();
	}
})(current, previous);

 

-Anurag

View solution in original post

Moin Kazi
Kilo Sage
Kilo Sage

Hi @Nagurbee1 ,

 

Please follow the steps below that I've completed for the change request table. You can replace the change request with the case table in the GlideRecord object.

 

Establish a business rule on the sysapproval_approver table that activates when the state changes to either approved or rejected.

In the script, we will use GlideRecord to ensure that the changes apply exclusively to the specified table and will update the work notes accordingly.

MoinKazi_0-1729863971852.png

 

MoinKazi_1-1729864010472.png

 

Output : 

MoinKazi_2-1729864080517.png

 

You can modify the business rule condition according to your needs; this is just an example of how to achieve your requirements.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi
www.linkedin.com/in/moinuddinkazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

View solution in original post

7 REPLIES 7

Moin Kazi
Kilo Sage
Kilo Sage

Hi @Nagurbee1 ,

 

Please follow the steps below that I've completed for the change request table. You can replace the change request with the case table in the GlideRecord object.

 

Establish a business rule on the sysapproval_approver table that activates when the state changes to either approved or rejected.

In the script, we will use GlideRecord to ensure that the changes apply exclusively to the specified table and will update the work notes accordingly.

MoinKazi_0-1729863971852.png

 

MoinKazi_1-1729864010472.png

 

Output : 

MoinKazi_2-1729864080517.png

 

You can modify the business rule condition according to your needs; this is just an example of how to achieve your requirements.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi
www.linkedin.com/in/moinuddinkazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

Hello Moin

Thank you so much for your solution, it has worked for me and accepting your solution.

 

Thank you

Nagurbi

 

Runjay Patel
Giga Sage

Hi @Nagurbee1 ,

 

Do the following.

 

1. create one Async BR.

RunjayPatel_0-1729865044290.pngRunjayPatel_1-1729865069956.png

 

Code

    var grec = new GlideRecord("change_request"); // replace with your table name
    grec.addQuery("sys_id", current.document_id);
    grec.query();
    if (grec.next()) {
        grec.work_notes = 'Approval comment:  ' + current.comments.getJournalEntry(1);
        grec.update();
    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------