How to move the approval /rejection status to work notes in ritm

jobin1
Tera Expert

Hi All

 

In ritm form is some one is approved or rejected the approval then the same message has to be updated in work notes as well, How we can achieve this?

find_real_file.png

1 ACCEPTED SOLUTION

@jobin 

No No. Please see my updated comment . I am posting it again with details which you need to try:

BR Details:

Table name: sysapproval_approver

When: After Update

Condition: Comments Changes

Script:

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

	// Add your code here
	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('sys_id',current.sysapproval);
	gr.query();
	if(gr.next()){
		gr.work_notes = current.comments.getJournalEntry(1);
		gr.update();
	}

})(current, previous);

BR:

find_real_file.png

Result:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

11 REPLIES 11

@jobin 

Since you want the comments to be moved only during rejection; you add this condition in your after update BR

current.source_table == 'sc_req_item' && current.state == 'rejected' && current.comments.changes()

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

shloke04
Kilo Patron

Hi,

Write a Before Update Business Rule on Approval table and use the script below:

Table: sysapproval_approver

Before Update

Condition: Comments Changes

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

	// Add your code here
	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('sys_id',current.sysapproval);
	gr.query();
	if(gr.next()){
		gr.work_notes = current.comments;
	}

})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

shloke04
Kilo Patron

Below code is tested. Use this ins an After Update BR:

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

	// Add your code here
	var gr = new GlideRecord('change_request');
	gr.addQuery('sys_id',current.document_id);
	gr.query();
	if(gr.next()){
		gr.work_notes = current.comments.getJournalEntry(1);
		gr.update();
	}

})(current, previous);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

shloke04
Kilo Patron

@jobin 

Attching the screenshot of the BR as well and Result:

Code to be used:

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

	// Add your code here
	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('sys_id',current.sysapproval);
	gr.query();
	if(gr.next()){
		gr.work_notes = current.comments.getJournalEntry(1);
		gr.update();
	}

})(current, previous);

BR:

find_real_file.png

Result:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

shloke04
Kilo Patron

Let me know if you are facing an issue. Since Comments is a Journal field you need to use "getJournalEntry(1)" to get the last update comments and copy it to the RITM work notes.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke