Removing Emojis from emails - without converting to String first

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 09:02 PM
Hi Team,
We receive a number of emails in our instance with Emoi's - Out of the box ServiceNow doesn't handle these and the emails are cut-off from the place where the emoji is, which means we lose critical information.
I implemented the below Business rule, before/insert with the code below which works great.
(function executeRule(current, previous /*null when async*/) {
// emoticons truncate emails, so remove them prior to insert
gs.log ("Cleaning up Email to remove Unicode");
current.body_text = current.body_text.toString().replace(/^[\0\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ' - ');
current.body = current.body_text.toString().replace(/^[\0\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, ' - ');
})(current, previous);
But (there's always a but!) as the email is now converted to String the email loses it's HTML and now looks like the below:
Without the rule it looks like this - much friendlier for our users:
Can anyone shed some light on how I could remove Emoji's without converting to a String first?
Appreciate any assistance!
Thanks Carl.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2018 10:55 PM
Hi,
Please check for below link,
Tip: Images in Express, and in emails Tip: Images in Express, and in emails
this may help you.
Thanks,
Tripti S.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2018 02:39 PM
Hi Tripti,
I'm not sure how that article helps - I'm not looking to manage images, but stop Emoji chars from cutting off the emails.
Thanks
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2018 06:09 PM
I originally followed this article for the fix.
However - recommended fix 1 didn't work so I used fix 2 which converts it to String first. Has anyone successfully implemented the first example function, as shown below, to work correctly on their instance?
- Create a new Business Rule
- Table
sys_email
- When to run:
before
insert
- Enable the Advanced checkbox
- Empty the Script field and insert the following code:
function remove4ByteUTF8Unicodecharacters(a) { return a ? a.replace(/^[\0\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "") : "" }; |
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 03:38 AM
Good morning Carl,
I too would like to see a working version of that script as well. I did note your existing business rule, but as you stated, it effectively strips out the HTML email and makes it plain text, so the formatting goes awry in those cases.
After the Kingston upgrade, I could see that the email body strings are set to string (UTF-8) so when looking at System Logs > Emails, I could see the emojis in the body when received. There looks like the comments and work notes, being journal fields, can't handle UTF-8 fully hence the cutoff of the emojis when the incident / task etc is being updated with those comments.
It'd either be sensible for SN to fix the settings for those journal fields or provide a working script that can cut it out from the HTML body directly - even possibly have it as an email system option to make it easier for admins.