Implementation of custom functions for runtime
- Last Updated: June 27, 2023
- 2 minute read
- Corticon.js
- Documentation
At runtime, the wrapper that calls the decision service uses the configured custom functions. You export them using the following syntax:
module.exports={name of function as used in rulesheet:reference to custom function};
For example:
module.exports={getSessionData:getSessionData};
which can be abbreviated as module.exports
={getSessionData};
The following code shows a more complete example with two custom functions:
|
These definitions enable you to use getSessionData
from session data as custom function names in any of
the simplified extended operators.
The custom functions can be:
- Shared across several decision services.
- Developed and managed with your own build pipeline.
The custom functions are specified in the implementation object using the attribute "customFunctions".
This attribute points to an array of object literals. Each object literal contains the information for one custom function.
{ <name of function as used in rulesheet>: <reference to custom function> }For example, here is the implementation file for the custom function examples in previous section:
|
|
Get custom function signature
A custom function must have the following signature:
function
<functionName> ( helper, name )
The name parameter contains the second argument string as entered in the Rulesheet editor.
Ent1.str1 = getString('getSessionData','key2')The getSessionData custom function
name parameter will contain the string key2.
The helper function is an object literal containing references to Decimal and DateTime operators.
helper={'decimal': <all decimal operators>,
'dateTime': <all dateTime operators> }How to write the implementation of custom functions for runtime
You can implement the body of a custom function with whatever logic your use case requires.
The only constraints are:
- The custom function has the proper signature.
- You return the proper object type. A
getDecimalcall needs to return a Decimal, likewise agetDateTimeneeds to return a DateTime. - You use the helper object to create or operate on Decimal and DateTime objects.
Custom GET functions
|