The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Approval Reminder Emails

Community Alums
Not applicable

I am working on a catalogue request approval reminder scheduled job, using this article as the basis:

How to Create an Open Approvals Reminder Email

I've searched the community and found lots of useful info, but not exactly what I'm looking for. Everything is working as expected, except for one part. I am trying to get the '${mailto:mailto.approval}' and '${mailto:mailto.rejection}' templates to work within the mail script.

Here is my code for the scheduled job:

var answer = [];

var eQuery = "sys_created_onRELATIVELT@dayofweek@ago@3";

var app = new GlideRecord('sysapproval_approver');

app.addQuery('state','requested');

app.addQuery('sysapproval.sys_class_name', 'sc_request');

app.addEncodedQuery(eQuery);

app.orderBy('approver');

app.query();

while(app.next()){

  answer.push(app.approver.sys_id);

}

for (var i = 0; i < answer.length; i++) {

  gs.eventQueue('request.approval.reminder', app, answer[i]);            

}

Here is the mail script:

var app = new GlideRecord('sysapproval_approver');

app.addQuery('state','requested');

app.addQuery('approver',event.parm1);

app.addQuery('sysapproval.sys_class_name','sc_request');

app.query();

while(app.next()){

  var scr = new GlideRecord('sc_request');

  scr.get(app.sysapproval);

  template.print('<p>You have an open request approval for ' + scr.number + ' from ' + scr.requested_for.name + '</br>');

  template.print('Request Short Description ' + scr.short_description + '.</p></br></br>');

  template.print("<a href=mailto:" + mailto.approval + "></a>");

  template.print("<a href=mailto:" + mailto.reject + "></a>");

  }

The logs are showing errors about 'mailto' not being defined, which makes sense. Is there a way to call a mail template within a mail script? If I add the mailto into the notification after calling the mailscript, it parses correctly, but as it's not within the while loop, the incorrect variables are passed to the link. i.e for all twenty notifications are sent out with the same REQ number and URL.

Is this just a case of having to manually recreate the reject and approval email links? The entire mailto: link looks like this:

mailto:instance@service-now.com?subject=Re%3AREQ0010795%20-%20reject&body=Please%20enter%20a%20reason%20this%20request%20is%20being%20rejected%20above.Do%20not%20edit%20below%20this%20line------------------------------------------Ref%3AMSG0285512%20

The issue then being, how do I capture the ref MSGID of the current email record?

Any insight is appreciated!

Cheers,

Tim

1 ACCEPTED SOLUTION

Keith Mills
Giga Guru

Tim, I would suggest using the built in notifications by just simply generating an event with the sys_id of each approval record, then using the message field on the notification record to send out the mailto links.   Use this in the Scheduled Job, and move all your mail to code into the notificaiton.



  1. var answer = [];  
  2. var eQuery = "sys_created_onRELATIVELT@dayofweek@ago@3";  
  3. var app = new GlideRecord('sysapproval_approver');  
  4. app.addQuery('state','requested');  
  5. app.addQuery('sysapproval.sys_class_name', 'sc_request');  
  6. app.addEncodedQuery(eQuery);  
  7. app.orderBy('approver');  
  8. app.query();  
  9. while(app.next()){    
  10. gs.eventQueue('request.approval.reminder', app, app.approver);                
  11. }  

View solution in original post

5 REPLIES 5

Derek10
Tera Expert

We used events to get the email to field and carried it to parm1, then used the built in option Event parm 1 contains recipient.



It seems that is the only part you are missing with the undefined error.                                              


Keith Mills
Giga Guru

Tim, I would suggest using the built in notifications by just simply generating an event with the sys_id of each approval record, then using the message field on the notification record to send out the mailto links.   Use this in the Scheduled Job, and move all your mail to code into the notificaiton.



  1. var answer = [];  
  2. var eQuery = "sys_created_onRELATIVELT@dayofweek@ago@3";  
  3. var app = new GlideRecord('sysapproval_approver');  
  4. app.addQuery('state','requested');  
  5. app.addQuery('sysapproval.sys_class_name', 'sc_request');  
  6. app.addEncodedQuery(eQuery);  
  7. app.orderBy('approver');  
  8. app.query();  
  9. while(app.next()){    
  10. gs.eventQueue('request.approval.reminder', app, app.approver);                
  11. }  

Community Alums
Not applicable

That makes more sense. Thanks Keith!


Chuck Tomasi
Tera Patron

Hi Tim,



Something you might be interested in that could have helped here...


Scriptless Scheduled Jobs