- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2013 08:00 AM
I am redesigning our current emails and its become a requirement that the description field on the email be shortened if it gets over a certain length and ... be put in its place.
My code is below but no matter what i do i cannot get it to print the result. (i'm using 25 characters as an example.)
<mail_script> var string = current.description; if(string.length > 25) { var short = string.substring(0, 24)+"..."); template.print(short); </mail_script>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2013 08:47 AM
Neil,
Try the below code, it works in the demo site.
<mail_script>
var strVar = current.description.toString();
if (strVar.length > 25) {
var strVar = strVar.substring(0, 25) + "...";
}
template.print(strVar);
</mail_script>
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2013 08:47 AM
Neil,
Try the below code, it works in the demo site.
<mail_script>
var strVar = current.description.toString();
if (strVar.length > 25) {
var strVar = strVar.substring(0, 25) + "...";
}
template.print(strVar);
</mail_script>
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2013 12:51 AM
Excellent thanks, works like a charm

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 09:35 AM
This is exactly what I needed. Thank you both!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2017 10:15 AM
If it's helpful, I added a little bit of html to mine to set it apart from other text in the email script. SNOW's script editor also pointed out the extra 'var' declaration in line 05 of your script; I removed it and it worked fine (it was just a warning at any rate).
Here's the whole email script I'm using for "incident_additional_details":
(function runMailScript(current, template, email, email_action, event) {
template.print('<p><font size="3" color="#4d4d4d" face="helvetica"><u>');
template.print(gs.getMessage('Additional Details'));
template.print('</u></font></p>');
template.print('<font size="3" color="#4d4d4d" face="helvetica">');
template.print('<p>' + gs.getMessage('Customer') + ': ${caller_id}<br/>');
template.print('<p>' + gs.getMessage('Category') + ': ${category}</p>');
template.print('<p>' + gs.getMessage('Priority') + ': ${priority}</p>');
template.print('<p>' + gs.getMessage('Description Preview') + ':<br/>');
template.print('<BLOCKQUOTE><i>');
var strVar = current.description.toString();
if (strVar.length > 150) {
strVar = strVar.substring(0, 150) + "...";
}
template.print(strVar);
template.print('</i></BLOCKQUOTE></p></font>');
})(current, template, email, email_action, event);
Result: