- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2015 08:09 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2016 06:33 AM
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.
- 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()){
- gs.eventQueue('request.approval.reminder', app, app.approver);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 12:59 PM
Thanks Chuck!