Customized data access operators
- Last Updated: June 21, 2023
- 3 minute read
- Corticon.js
- Documentation
Corticon.js provides data access operators in a mechanism that will execute custom JavaScript functions. The custom functions are accessed as a group of built-in operators available from Studio's Rule operator tree under General > Functions as standalone GET and SET operators for each Corticon.js data type:
Each get operator works the same way;
only the returned data type is different. Each set
operator works in a fashion similar to the get
operators yet each has an additional parameter, the value to
set. Set operators do not return any data as they are void operators.
The project for SampleJS Get Set Operators
- Perform the tasks in Accessing sample Corticon.js projects.
- In Studio, create a new Rule Project, and name it GetSetOperators.
- Choose File > Import > Existing Projects into Workspace.
- In your staging location, navigate to ExtendedOperators > BasicSampleGetSetOperators.
- Select all the files at that location, and then drag the files to copy them into your Rule Project.
The sample's Rulesheet getData
get function takes two
parameters: - The name of the custom function to call.
- A string parameter. For multiple parameters, the JSON string can encapsulate all the parameters to pass to the custom function.
The sample Rulesheet getData.ers
shows each data type with data to fetch.
For example, to call the custom function getData with parameter key2 using the
getString operator, the result is stored in the
string attribute, Ent1.str2.
The sample's Rulesheet setData
![]()
A custom set function takes three
parameters:
- The name of the custom function to call.
- A string parameter. If you need to pass more than one parameter, the JSON string can encapsulate all the parameters to pass to the custom function.
- The value to set. The type of this parameter corresponds to the
operator name. For example,
setDateTime, requires aDateTimeobject.
How to set a mock implementation for the Studio tester
Studio tester runs the Ruleflows and Rulesheets in the context of a local Node.js process. Consequently, it is possible that:
- the production environment data may not be available
- the production context is not available. For example, in studio tester the browser session context or the Serverless function context is not available .
However, you can specify a mock implementation to run local unit tests by appending the implementation to the project. The configuration of the extensions is in the sample's configuration file:
|
setData with the parameter key5 using the setDecimal operator, use the action sessionData.set('key5',
helper.decimal.outputToJson(value) as shown in the mock implementation.
The result is stored in the string attribute, Ent1.decimal1.The functions from the configuration file are needed for testing as well bundling into production packaging.
- In Corticon.js Studio, open your project.
- Click on your project, and then select Properties.
- Select Corticon.js Extensions.
- Click Add, and then select your
.jsimplementation file, as illustrated:
- Click Apply and Close.
Running the sample's Ruletest

getSetDataTest.ert, and then
run it: 