How can we get rejected comments in notifications using mail script from Approval table

Raj90
Tera Guru

I wrote an email script.

Email script:-  rejected_comments

 var gr = new GlideRecord('sysapproval_approver');
       gr.addQuery('state','rejected'); or)
       gr.addQuery('document_id',current.sys_id);
      gr.query();
while(gr.next()) {
gs.template(gr.comments.getJournalEntry(1));
}

I called the email script in Notifications body like in the below way

 ${mail_script:rejected_comments}

But in notifications, I'm not getting comments.

Thanks

Raj

 

11 REPLIES 11

amlanpal
Kilo Sage

Hi Raj,

 

Please use the script given below and give it a try:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state','rejected');
gr.addQuery('sysapproval',current.sys_id);
gr.query();
while(gr.next()) {
	template.print(gr.comments.getJournalEntry(1));
}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan

 

Hi Amlan,

I tried but it's not working.

find_real_file.png

Thanks

Raj

Hi Raj,

 

I can see that you are trying the code in the background script. Please use the SysID of the record against which you are trying to get the rejection comments. But when you will be using the script in the mail script please use current.sys_id.

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state','rejected');
gr.addQuery('sysapproval','0f20c9f94f5d3300c1012f9ca310c7f0'); //Replace the SysID of your record here for Background Script validation
gr.query(); 
while(gr.next()) {
	template.print(gr.comments.getJournalEntry(1));
}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sys_id','07c01bd5db15bf00242d68d35b961939');


gr.query();
while(gr.next()) {
gs.print(gr.comments.getJournalEntry(1));

}

O/p:-Working fine

find_real_file.png

But the below one is not woeking means null only we are getting in notifications.

var gr = new GlideRecord('sysapproval_approver'); 
      gr.addQuery('sys_id',current.sys_id); (or) gr.addQuery('document_id',current.sys_id);      (or)gr.addQuery('sysapproval',current.sys_id); 

     gr.query();
while(gr.next()) { 
gs.template(gr.comments.getJournalEntry(1));

 

Thanks

 

Hi Raj,

 

In the email script please use the below script:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('state','rejected'); //Assuming you are looking for rejection comment. 
gr.addQuery('sysapproval',current.sys_id);
gr.query();
while(gr.next()) {
	template.print(gr.comments.getJournalEntry(1));
}

 

Hope this helps. Please mark the answer Correct/Helpful based on the impact.

Regards,

Amlan