Email Script Isn't Working

Community Alums
Not applicable

Hey All, 

 

I have an email script that works properly when I run it via the background script, but when I preview it for the email notification, it isn't working. 

 

My email notification is running off the change_request table, but I'm using the sysapproval_approver table for my GlideRecord query. 

 

Below is my script: 

 var gr = new GlideRecord("sysapproval_approver");
    gr.get(current.sysapproval);
    template.print("This is the approver who is rejecting the change request: " + gr.approver.getDisplayValue() + " from " + gr.group.assignment_group.getDisplayValue() + " has rejected this change. Please see rejection comments below and contact " + gr.approver.getDisplayValue() + " if you have questions. ");

 

But when I preview the notification, I get this: 

SampleV3.PNG

What am I doing wrong? Am I missing something? Does the method get no longer work? I'm confused b/c it is working as expected via the background script.

1 ACCEPTED SOLUTION

Akif_Shah
Kilo Sage
Kilo Sage

If the notification is on the change request table, the "current" object will be referencing the change request record triggering the notification. So current.sysapproval is not valid since there is no sysapproval field on change request.

So you need to use something like

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('document_id', current.sys_id);

gr.addQuery("state", "rejected"); // Filter out only approved record if you want all comment this line

gr.query();
if(gr.next()){
  template.print("YOUR CONTENT GOES HERE");
}

View solution in original post

9 REPLIES 9

SanjivMeher
Kilo Patron
Kilo Patron

Try gr.getDisplayValue('approver') or gr.approver.name 

and use gr.group.assignment_group.name


Please mark this response as correct or helpful if it assisted you with your question.

Harish KM
Kilo Patron
Kilo Patron

Hi @Community Alums can you Replace the

gr.get(current.sysapproval) to below

gr.addQuery('sysapproval', current.sys_id); 

Regards
Harish

maroon_byte
Mega Sage

In your query, current is the change_request table. Hence your filter needs to be:

 

gr.get("sysapproval",current.sys_id);
 
Also, best practice, don't use 'gr' in custom/personal queries. For your query, use grSA instead.
 
Regards,
Sharad

SanjivMeher
Kilo Patron
Kilo Patron

Also as suggested by others, you need to query by the sysapproval. Also you may need to add another addQuery, if you want to only show approval with Rejected state.

 

var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery('sysapproval', current.getValue('sys_id'));
gr.query();
if (gr.next())
{
    template.print("This is the approver who is rejecting the change request: " + gr.getDisplayValue('approver') + " from " + gr.group.assignment_group.name+ " has rejected this change. Please see rejection comments below and contact " + gr.approver.name + " if you have questions. ");
}

 


Please mark this response as correct or helpful if it assisted you with your question.