Utils

(utils)

Methods Summarized

Methods Detailed

base64ToBytes(base64String:)

Return the byte array representation of the Base64 value

Parameters

  • Object base64String: the Base64 encoded string to convert to byte array

Returns: Array byteArray representation of the base64 string using UTF-8 charset for conversion

Sample

var string = utils.base64ToBytes(base64String);

base64ToString(base64String:)

Return the String representation of the Base64 value

Parameters

  • Object base64String: the Base64 value to convert to String

Returns: String String decoded representation of the Base64 value using UTF-8 charset for conversion

Sample

var string = utils.base64ToString(base64Value);

bytesToBase64(byteArray:)

Return the Base64 value representation of the byteArray

Parameters

  • Object byteArray: the byte array to convert to Base64 value

Returns: String Base64 representation of the byte array using UTF-8 charset for conversion

Sample

var string = utils.bytesToBase64(byteArray);
x`

bytesToHex(bytearray)

Parameters

  • Array bytearray the byte array to convert to hex encoded string

Returns: String returns hex encoded string from bytearray

Sample

var string = utils.bytesToHex(byteArray);

bytesToString(byteArray:)

Return the string conversion of the byteArray

Parameters

  • Object byteArray: the byte array to convert to

Returns: String string representation of the byte array using UTF-8 charset for conversion

Sample

var string = utils.bytesToString(byteArray);

dateFormat(date, format)

Format a date object to a text representation.
This will format with the system timezone for the webclient
For NGClient it will use the timezone of the client, the same goes for the Smartclient (but that is the system timezone)
see #dateFormat(Date,String,String) for using the actual clients timezone.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'.
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)

Parameters

  • Date date the date

  • String format the format to output

Returns: String the date as text

Sample

var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss');

dateFormat(date, format, timezone)

Format a date object to a text representation using the format and timezone given.
If the timezone is not given the timezone of the client itself will be used.
see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)

Parameters

  • Date date the date

  • String format the format to output

  • String timezone The timezone string to use to parse the date (like GMT+3), if null then the timezone of the current client is used.

Returns: String the date as text

Sample

var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "UTC");

dateFormat(date, format, language, country)

Format a date object to a text representation.
This will format with the system timezone for the webclient
With language and/or country the locale will be created.
For NGClient it will use the timezone of the client, the same goes for the Smartclient (but that is the system timezone)
see #dateFormat(Date,String,String) for using the actual clients timezone.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'.
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)

Parameters

  • Date date the date

  • String format the format to output

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: String the date as text

Sample

var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "fr", "CA");

dateFormat(date, format, timezone, language, country)

Format a date object to a text representation using the format, timezone, language and country given.
With the language and country given, the locale will be created.
If the timezone is not given the timezone of the client itself will be used.
see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'
Symbols meaning is:
 G        era designator
 y        year
 Y        week year
 M        month in year
 d        day in month
 h        hour in am/pm (1~12)
 H        hour in day (0~23)
 m        minute in hour
 s        second in minute
 S        millisecond
 E        day in week
 D        day in year
 F        day of week in month
 w        week in year
 W        week in month
 a        am/pm marker
 z        time zone
 k        hour in day (1~24)
 K        hour in am/pm (0~11)

Parameters

  • Date date the date

  • String format the format to output

  • String timezone the timezone to use the format, if null then current client timezone is used.

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: String the date as text

Sample

var formattedDateString = utils.dateFormat(dateobject,'EEE, d MMM yyyy HH:mm:ss', "UTC", "fr", "CA");

getUnicodeCharacter(unicodeCharacterNumber)

Returns a string containing the character for the unicode number.

Parameters

  • Number unicodeCharacterNumber the number indicating the unicode character

Returns: String a string containing the unicode character

Sample

//returns a big dot
var dot = utils.getUnicodeCharacter(9679);

hasRecords(foundset)

Returns true if the (related)foundset exists and has records. Another use is, to pass a record and qualified relations string to test multiple relations/foundset at once

Parameters

Returns: Boolean true if exists

Sample

//test the orders_to_orderitems foundset
if (myElement.hasRecords(orders_to_orderitems))
{
	//do work on relatedFoundSet
}
//test the orders_to_orderitems.orderitems_to_products foundset to be reached from the current record
//if (myElement.hasRecords(foundset.getSelectedRecord(),'orders_to_orderitems.orderitems_to_products'))
//{
//	//do work on deeper relatedFoundSet
//}

hasRecords(record, relationString)

Returns true if the (related)foundset exists and has records. Another use is, to pass a record and qualified relations string to test multiple relations/foundset at once

Parameters

  • JSRecord record A JSRecord to test.

  • String relationString The relation name.

Returns: Boolean true if the foundset/relation has records.

Sample

//test the orders_to_orderitems foundset
if (myElement.hasRecords(orders_to_orderitems))
{
	//do work on relatedFoundSet
}
//test the orders_to_orderitems.orderitems_to_products foundset to be reached from the current record
//if (myElement.hasRecords(foundset.getSelectedRecord(),'orders_to_orderitems.orderitems_to_products'))
//{
//	//do work on deeper relatedFoundSet
//}

hexToBytes(hex)

Parameters

  • String hex hex encoded string to be decoded into a byte array.

Returns: Array a byte array from hex encoded string

Sample

var array = utils.hexToBytes(hex);

hexToString(hex)

Parameters

Returns: String returns decoded string from hex

Sample

var string = utils.hexToString(hex);

isMondayFirstDayOfWeek()

Returns true when Monday is the first day of the week for your current locale setting.

Returns: Boolean true if Monday is first day of the week in current locale

Sample

if(utils.isMondayFirstDayOfWeek())
{
	//a date calculation
}

numberFormat(number, digits)

Format a number to have a defined fraction.

Parameters

  • Number number the number to format

  • Number digits nr of digits

Returns: String the resulting number in text

Sample

var textalNumber = utils.numberFormat(16.749, 2); //returns 16.75

numberFormat(number, digits, language, country)

Format a number to have a defined fraction.

Parameters

  • Number number the number to format

  • Number digits nr of digits

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: String the resulting number in text

Sample

var textalNumber = utils.numberFormat(16.749, 2, "fr", "CA"); //returns 16.75

numberFormat(number, format)

Format a number to specification.

Parameters

Returns: String the resulting number in text

Sample

var textalNumber2 = utils.numberFormat(100006.749, '#,###.00'); //returns 100,006.75

numberFormat(number, format, language, country)

Format a number to specification.

Parameters

  • Number number the number to format

  • String format the format

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: String the resulting number in text

Sample

var textalNumber2 = utils.numberFormat(100006.749, '#,###.00', "fr", "CA"); //returns 100,006.75

parseDate(date, format)

Parse a string to a date object. This parses the date using the TimeZone of the server Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

Parameters

  • String date the date as text

  • String format the format to parse the date

Returns: Date the date as date object

Sample

var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss');

parseDate(date, format, timezone)

Parse a string to a date object. Using the timezone that is given, if null then it formats it with the clients timezone.

see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

Parameters

  • String date the date as text

  • String format the format to parse the date

  • String timezone The timezone string to use to parse the date (like GMT+3)

Returns: Date the date as date object

Sample

var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss');

parseDate(date, format, language, country)

Parse a string to a date object. Using language and country that are given, if null then it formats it with the locale of the client

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

Parameters

  • String date the date as text

  • String format the format to parse the date

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: Date the date as date object

Sample

var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss', 'en', 'US');

parseDate(date, format, timezone, language, country)

Parse a string to a date object. Using the timezone, language and country that are given, if null then it formats it with the timezone and locale of the client

see i18n.getAvailableTimeZoneIDs() to get a timezone string that can be used.

Format can be a string like: 'dd-MM-yyyy' , 'dd-MM-yyyy HH:mm' , 'MM/dd/yyyy', 'MM/dd/yyyy hh:mm aa', 'dd.MM.yyyy'

Parameters

  • String date the date as text

  • String format the format to parse the date

  • String timezone The timezone string to use to parse the date (like GMT+3)

  • String language language used to create locale

  • String country country used along side language to create the locale

Returns: Date the date as date object

Sample

var parsedDate = utils.parseDate(datestring,'EEE, d MMM yyyy HH:mm:ss', 'GMT+3', 'en', 'US');

stringEscapeMarkup(textString)

Returns the escaped markup text (HTML/XML).

Parameters

  • String textString the text to process

Returns: String the escaped text

Sample

var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')

stringEscapeMarkup(textString, escapeSpaces)

Returns the escaped markup text (HTML/XML).

Parameters

  • String textString the text to process

  • Boolean escapeSpaces indicating to escape spaces

Returns: String the escaped text

Sample

var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')

stringEscapeMarkup(textString, escapeSpaces, convertToHtmlUnicodeEscapes)

Returns the escaped markup text (HTML/XML).

Parameters

  • String textString the text to process

  • Boolean escapeSpaces indicating to escape spaces

  • Boolean convertToHtmlUnicodeEscapes indicating to use unicode escapes

Returns: String the escaped text

Sample

var escapedText = utils.stringEscapeMarkup('<html><body>escape me</body></html>')

stringFormat(text_to_format, parameters)

Formats a string according to format specifiers and arguments.

Parameters

  • String text_to_format the text to format

  • Array parameters the array with parameters

Returns: String the formatted text

Sample

// the  format specifier has the syntax: %[argument_index$][flags][width][.precision]conversion
// argument index is 1$, 2$ ...
// flags is a set of characters that modify the output format
// typical values: '+'(The result will always include a sign), ','(The result will include locale-specific grouping separators)
// width is a non-negative decimal integer indicating the minimum number of characters to be written to the output
// precision is a non-negative decimal integer usually used to restrict the number of characters
// conversion is a character indicating how the argument should be formatted
// typical conversion values: b(boolean), s(string), c(character), d(decimal integer), f(floating number), t(prefix for date and time)
// Date/Time Conversions (used after 't' prefix):
		// 'H' 	Hour of the day for the 24-hour clock, formatted as two digits with a leading zero as necessary i.e. 00 - 23.
		// 'I' 	Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e. 01 - 12.
		// 'k' 	Hour of the day for the 24-hour clock, i.e. 0 - 23.
		// 'l' 	Hour for the 12-hour clock, i.e. 1 - 12.
		// 'M' 	Minute within the hour formatted as two digits with a leading zero as necessary, i.e. 00 - 59.
		// 'S' 	Seconds within the minute, formatted as two digits with a leading zero as necessary, i.e. 00 - 60 ("60" is a special value required to support leap seconds).
		// 'L' 	Millisecond within the second formatted as three digits with leading zeros as necessary, i.e. 000 - 999.
		// 'p' 	Locale-specific morning or afternoon marker in lower case, e.g."am" or "pm". Use of the conversion prefix 'T' forces this output to upper case.
		// 'z' 	RFC 822 style numeric time zone offset from GMT, e.g. -0800.
		// 'Z' 	A string representing the abbreviation for the time zone.
		// 'B' 	Locale-specific full month name, e.g. "January", "February".
		// 'b' 	Locale-specific abbreviated month name, e.g. "Jan", "Feb".
		// 'h' 	Same as 'b'.
		// 'A' 	Locale-specific full name of the day of the week, e.g. "Sunday", "Monday"
		// 'a' 	Locale-specific short name of the day of the week, e.g. "Sun", "Mon"
		// 'C' 	Four-digit year divided by 100, formatted as two digits with leading zero as necessary, i.e. 00 - 99
		// 'Y' 	Year, formatted as at least four digits with leading zeros as necessary, e.g. 0092 equals 92 CE for the Gregorian calendar.
		// 'y' 	Last two digits of the year, formatted with leading zeros as necessary, i.e. 00 - 99.
		// 'j' 	Day of year, formatted as three digits with leading zeros as necessary, e.g. 001 - 366 for the Gregorian calendar.
		// 'm' 	Month, formatted as two digits with leading zeros as necessary, i.e. 01 - 13.
		// 'd' 	Day of month, formatted as two digits with leading zeros as necessary, i.e. 01 - 31
		// 'e' 	Day of month, formatted as two digits, i.e. 1 - 31.

		// common compositions for date/time conversion
		// 'R' 	Time formatted for the 24-hour clock as "%tH:%tM"
		// 'T' 	Time formatted for the 24-hour clock as "%tH:%tM:%tS".