- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2018 12:02 PM
I've updated an email template, however just not showing the links/message. Not sure what I am missing here. The notification fires when a comment is made on the request table and is sent to the 'request for'. I have a mail script to identify is the request for is an internal user or not and handle accordingly.
Short description: ${short_description}
Item: ${cat_item}
</br>
<mail_script>
var internal = current.Request.Requested for.u_internal_user;
function(){
if (internal != 'No') {
return 'To view Request: ${URI_REF}';
}
else if (internal == 'No') {
return 'To view Request: <a href="' + gs.getProperty('glide.servlet.uri') + 'msp/' + '">Click Here</a>';
}
}
template.print();
</mail_script>
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2018 11:24 AM
Great! Yeah so variables in email scripts are scoped to the individual script. You don't have a 'internal' variable defined in the second email script block, and it looks like there is an extra unmatched }, and some mismatched quotations so it fails.
You can also use a try catch block to display the error like this.
<mail_script>
try{
if (internal != 'No') {
template.print('To view Request (this is SSO): ${URI_REF}');
} else if (internal == 'No') {
template.print('To view Request (this is MSP): <a href="PORTAL URL HERE">Click Here</a>');
}else template.print('To view Request (this is else SSO): ${URI_REF}');
} catch(err){
template.print('An error occurred - '+err.message);
}
</mail_script>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2018 01:08 PM
Hi Corey,
I'm not sure what you're trying to do with that function, but you aren't printing anything. That template.print() statement contains no string parameter.
Please view these email scripting examples to understand the template.print function. Example scripting for email notifications
That being said, here is what I'm assuming you mean to do. Hope this help!
Short description: ${short_description}
Item: ${cat_item}
</br>
<mail_script>
var internal = current.Request.Requested for.u_internal_user;
if (internal != 'No') {
template.print('To view Request: ${URI_REF}');
}
else if (internal == 'No') {
template.print('To view Request: <a href="' + gs.getProperty('glide.servlet.uri') + 'msp/' + '">Click Here</a>');
}else template.print('Internal undefined');
</mail_script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2018 11:27 AM
I've gotten here but still cannot get it to find my internal user. - On the user record we have an internal yes/no identifier. I am fairly confident what I have in bold is my issue.
My notification is producing the SSO hyperlink still. Any help is much appreciated.
Notification Message:
Short description: ${short_description}
Item: ${cat_item}
Request: ${request}
</br>
<mail_script>
var gr_req = new GlideRecord('sc_req_item');
gr_req.get(current.number);
var internal = current.requested_for.u_internal_user;
if (internal != 'No') {
template.print('To view Request (this is SSO): ${URI_REF}');
}
else if (internal == 'No') {
template.print('To view Request (this is MSP): <a href="' + gs.getProperty('glide.servlet.uri') + 'msp/' + '">Click Here</a>');
}else template.print('To view Request (this is else SSO): ${URI_REF}');
</mail_script>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2018 07:01 AM
Looking back, I did make a couple mistakes, yeah that current.requested_for.u_internal_user should be the correct syntax.
I'd recommend just printing that internal user value to verify what it's returning, so do a template.print("Value is "+current.requested_for.u_internal_user);
I doubt it, but the dot walking to that field could be the issue, in which case you could do the following. You don't really need to do another GlideRecord to the sc_req_item since you already have access to all the fields from current.
var gr_user = new GlideRecord('sys_user');
if(gr_user.get(current.requested_for)){
var internal = gr_user.getValue('u_internal_user');
template.print("Internal is " + internal);
}else{
//requested for was empty
template.print("Req for empty");
}
Let me know what some of your outputs are, and I can try to assist further. You'll need to alter your MSP URL if you want to go to that record also. You'll need to specify the table and sys_id in the URL string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2018 07:29 AM
I think we're getting close here, I can return (showing in the email log) the correct values from mail script below. However, the second block I cannot return either IF statement.
<mail_script>
var gr_req = new GlideRecord('sc_req_item');
gr_req.get(current.number);
var internal = current.u_task_for.u_internal_user;
template.print("Task for " + current.u_task_for + "\n");
template.print("Number is " + current.number + "\n");
template.print("Internal " + internal);
</mail_script>
<mail_script>
if (internal != 'No') {
template.print('To view Request (this is SSO): ${URI_REF}');
}
else if (internal == 'No') {
template.print('To view Request (this is MSP): "<a href=""PORTAL URL HERE"">Click Here</a>");
}else template.print('To view Request (this is else SSO): ${URI_REF}');
}
</mail_script>