You are here: Offline capability > Function rule support in offline mode > How to call a JavaScript function directly

How to call a JavaScript function directly

In your custom JavaScript code, you can directly call a JavaScript utility function that is defined in the one of the libraries listed in Function rule support in offline mode.

pega.functions.LIBRARY_NAMESPACE.FUNCTION_NAME(PARAMETER_1, ...);

Where LIBRARY_NAMESPACE is the 'Library' string that is appended to the name of the library, and FUNCTION_NAME is the name of the function rule.

Examples

The following JavaScript example shows how to directly call the isInThePast() utility function, with a single parameter specifying date and time, that is part of the Default library. If applicable, the argument can be a JavaScript value or object or a Pega Platform string type.

if ( pega.functions.DefaultLibrary.isInThePast( {dateAndTime : new Date(2015, 10, 27, 16, 23, 00)} ) {
	console.log("Date " + dataAndTime + " is in the past!");
	}

Some utility functions in the libraries listed above might have several signatures that do not adhere to the standard JavaScript naming convention. For example, for the DateTime library, the CompareDates() function has the following signatures:

CompareDates()
	CompareDates--(String,String,boolean)

The following JavaScript example shows how to call the utility function with the second signature.

if ( pega.functions.DateTimeLibrary["CompareDates--(String,String,boolean)"]( 
	dateOne, 
	dateTwo, 
	true )} ) {
		console.log("Date " + dateOne + " is before " + dateTwo + "!");
	}