Skip to main content

Posts

Showing posts from August, 2020

Converting Number from Scientific "E" Notation to GlideDateTime in ServiceNow

Today I hit a frustrating issue with a data import where a couple of fields which contained Unix date/time information were being received in scientific notation (e.g. 1.59855015616942E9).  How do we turn this into something we can use in ServiceNow? Requirements Convert a Unix Epoch timestamp, stored as number of seconds since 1970-01-01 00:00:00, in scientific 'e' notation (e.g. 1.59855015616942E9) into a GlideDateTime object containing the appropriate value (e.g. 2020-08-27 17:42:36). Approach Try not to tear out your hair figuring this one out! Implementation Make sure your number is actually a number (using the Number() function), then convert that into the number of milliseconds since the Unix epoch, then use the setValue() function on a GlideDateTime object to get a useful variable. var evilNumber = '1.59855015616942E9'; var gdt = new GlideDateTime(); // Make sure evilNumber is actually a number by using JavaScript Number() function. // Then multiply it by 1000 ...

Converting Number from Scientific "E" Notation to GlideDateTime in ServiceNow

Today I hit a frustrating issue with a data import where a couple of fields which contained Unix date/time information were being received in scientific notation (e.g. 1.59855015616942E9).  How do we turn this into something we can use in ServiceNow? Requirements Convert a Unix Epoch timestamp, stored as number of seconds since 1970-01-01 00:00:00, in scientific 'e' notation (e.g. 1.59855015616942E9) into a GlideDateTime object containing the appropriate value (e.g. 2020-08-27 17:42:36). Approach Try not to tear out your hair figuring this one out! Implementation Make sure your number is actually a number (using the Number() function), then convert that into the number of milliseconds since the Unix epoch, then use the setValue() function on a GlideDateTime object to get a useful variable. var evilNumber = '1.59855015616942E9'; var gdt = new GlideDateTime(); // Make sure evilNumber is actually a number by using JavaScript Number() function. // Then multiply it by 1000 ...

Restricting Outbound Email by Domain Whitelist in ServiceNow

A while ago I came across a requirement to limit outbound emails sent by domain.  Of course there is an out of the box solution already available to restrict inbound email, but I struggled to find something that would restrict out-going email in the same way.  This requirement could help comply with Data Loss Prevention (DLP) policies. You could do this (and many other things) using your own email infrastructure, but I wanted to see if we could do this without resorting to that. I found a way to use a business rule, a custom system property, and (optionally) an event to build something that met the requirements and I originally posted it via the ServiceNow community in the hopes it might be useful to others.  I'm re-posting it here with some minor updates in the same vein! Requirements Prevent any email from any part of the platform from being sent to a domain not on a predefined list of safe domain names; the White-List. Flag any attempt to send to a domain not on the W...