You are here: Offline capability > Function rule support in offline mode > Offline function rule API

Offline function rule API

The offline function rule API consists of a JavaScript method that allows you to run a function rule in offline-enabled applications by using a Run script action or a custom JavaScript function.

The following JavaScript method is available for the pega.offline object:

Method

Description

runFunction( functionName, functionLibrary, parameters )

A synchronous method that runs a function rule in offline mode with the specified name. It returns the return value that is specified for the function.

The method has the following parameters:

    functionName Required. Specifies the name of the function rule to run.
    functionLibrary Required. Specifies the name of the class that the function rule belongs to.
    parameters Specifies the map of input parameters that are defined on the function rule. The parameter name must match the name of the parameter defined in the model of the utility function rule. The input parameters can be provided as standard JavaScript values or object, or a Pega PlatformString representing specific type.

Examples

The following sample JavaScript code allows you to run a function rule called isInThePast, which belongs to the Default class, passing as a single parameter a Pega PlatformDateTime String type. The purpose of this function is to check whether the specified date is in the past.

if ( pega.offline.runFunction("isInThePast", 
	"Default", 
	{dateAndTime : "20151027T162300.000 GMT" }) ) { 
		console.log("Date " + dateAndTime + " is in the past!");
	}

The following sample JavaScript code allows you to run the same function rule as above, passing as a single parameter a Date JavaScript object instead.

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