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

Hi raj,

 

Did you able to validate my last response? Please let me know if you are still facing the issue.

 

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

Regards,

Amlan

Santhana Rajhan
Mega Sage

Check if this works.

Create an event and trigger it when an approval is rejected.

 

Create an event

Event: rejection_mail

Table: Approval table

Fired by: Business Rule

Business Rule:

Trigger Notification on Reject

Table: approval table

When to run: After 100 on insert and update

Advanced script:

if(current.state.changesTo('27')){ //Mention the value of the state
if(current.u_request_raised_for == 'myself'){
gs.eventQueue("rejection_mail", current, current.caller_id, gs.getUserID()); //Trigger rejection_mail event
}
if(current.u_request_raised_for == 'someone_else'){
gs.eventQueue("rejection_mail", current, current.u_requested_for, gs.getUserID()); ////Trigger rejection_mail event
}

 

Use the below Notification email script 

Name: comments

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	var comments = current.comments.getJournalEntry(1);
	template.print(comments);
	
})(current, template, email, email_action, event);