Singleton Design pattern

The importance of this pattern is coming from the fact that There are many objects we only need one of, like objects that handle
preferences and registry settings, objects used for logging.
In fact, for many of these types of objects, if we are to instantiate more than one time we will run into all sorts of problems like incorrect program behavior, overuse of resources.
lets how we can constract a class that can work as Singleton . in order to write this class you need to follow these steps Continue reading “Singleton Design pattern”

Convert date to UNIX time stamp

lets start off with getting to know what is Unix time stamp.
UNIX time stamp is a way to track time in seconds, the tracking start from 01-01-1970.
in ServiceNow,sometimes we are in need for this kind of format especially in integration tasks . the function below would make it easy to convert glide date to UNIX time stamp ūüôā
function ConvertToUnix(passdate){
// Import Java Date Class
var Date = Packages.java.util.Date;
//get glide date object
var gdt =passdate.getGlideObject();
// create instance from date object . pass date as milliseconds . getNumericValue() would do the job
var date = new Date(gdt.getNumericValue());
// getTime converts date to unix time stamp
var diff = date.getTime();
// return unix time stamp
return diff;
}

GlideDate to ISO 8601

as i start this article, i have a confusion to say . i really hate working with date:).however,if you are dealing a lot with custom integration you probably notice that working with date in ServiceNow is more a complex.
in some cases, like for example sending date in SOAP Message, you need to follow ISO-8601 standard . The example below,shows how to convert GlideDate to  ISO 8601 with two different format

2014-09-02T11:28:56+00:00
2014-09-02T11:28:56Z
Continue reading “GlideDate to ISO 8601”