How to populate MailTo Body with request variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 10:56 AM - edited 04-29-2024 11:01 AM
I have a requirement to modify the MailTo script to change the Subject and Body. I used the following to modify the mail script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var subjectTxt = encodeURI('Re:' + current.number + ' - Accept Access Attestation');
var bodyTxt = encodeURI('Please provide a business justification for your Access Attestation: ');
template.print('<a title="click here" href="mailto:YOURINSTANCEEMAIL@service-now.com?SUBJECT=' + subjectTxt + '&body='+ bodyTxt+ bodyTxt+'">Click here</a>');
}
However, the subject does not put the correct requested item number, and I have not been able to get the options variables to populate in the body.
I dont mind printing the variables individually rather than as a loop etc. simple is great at this point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 01:23 PM
To set the subject correctly, you need to use email.setSubject:
email.setSubject(subjecttxt);
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 01:55 PM
Hi @Nathan Okh,
Can you confirm if your notification is created on the [sc_req_item] table?
I have copied your code and the subject looks fine to me.
In regards to getting all the variables, try the following script.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var subjectTxt = encodeURI('Re:' + current.number + ' - Accept Access Attestation');
var bodyTxt = 'Please provide a business justification for your Access Attestation: \n';
var variables = current.variables.getElements();
var vquest;
for (var key = 0; key < variables.length; key++) {
vquest = variables[key].getQuestion();
bodyTxt += vquest.getLabel() + " : " + vquest.getDisplayValue() + "\n";
}
template.print('<a title="click here" href="mailto:YOURINSTANCEEMAIL@service-now.com?SUBJECT=' + subjectTxt + '&body=' + encodeURI(bodyTxt) + '">Click here</a>');
})(current, template, email, email_action, event);
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 07:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 10:54 AM
I am pretty in the same way.
Navigate to System Notification > Email > Notification Email Scripts. to Create a email script
Navigate to > Email Client Templates, and add it there. Ex. ${mail_script:your_script_name}