Programme Utility Methods

Programme Utility Functions

These methods can be used within any programme step that allows the use of javascript.

getVal

_i.utils.getVal(<queryObject>, <element>, <defaultValue>);

queryObject - Base object.
element - An array of the field you are looking for. This can be any level deep.
defaultValue - (optional) Returned value if element is not present in object. Will return null by default if no value is not specified.

The getVal function is used to ensure that conditional variables you are working with never get returned as undefined. This function will return a 'default' value if the data your working with doesn't exist or hasn't been defined. See usage example below:

function(data){
	var eventId = _i.utils.getVal(data, ["Event Id"], false);
	logger.info(eventId);
}

If data['Event Id']  exists then the value of data['Event Id'] is returned. 

If data['Event Id']  doesn't exist (undefined) the third parameter of this function is returned. In the above example the variable 'eventId' would equal false.

parseDateValue

_i.utils.parseDateValue(<date>);

date - Date to be parsed.

The parseDateValue function is used to parse a date stored in a programme's programme data, whatever it's format. So whether the format is a string, object, or number It will correctly parse the date.

It can be combined with moment.js as in the following example:

moment(_i.utils.parseDateValue(data["__trigger"]["Booking"]["Arrival Date"])).month();):

function(data){ 	
	var month = moment(_i.utils.parseDateValue(data["__trigger"]["Booking"]["Arrival Date"])).month();):	
	logger.info(month); 
} 

Still need help? Contact Us Contact Us