To define a Corticon.js service callout in JavaScript, you must follow guidelines for its four parts:
  1. Metadata definition
  2. Service callout function implementation
  3. Configure runtime properties
  4. Export actions

Metadata definition

The metadata definition of the service callout is what gets populated and displayed in the Corticon.js Studio Ruleflow Editor. Here is an example of the metadata definition of a Service Callout:
const updateData = {
    func: 'updateCargoEntity',
    type: 'ServiceCallout',
    description: {'en_US': 'updates the entity'},
    extensionType: 'SERVICE_CALLOUT',
    name: { 'en_US': 'updateData' }
};

The metadata definition has the following fields:

  • func (required) - The actual functional definition of the service callout code that gets executed at runtime by the Corticon engine.
  • type (required) - ServiceCallout A string value that defines the type required by a Corticon.js Studio Service Callout.
  • description - Object, where the keys are locales (as strings) and the values are localized strings used for the description of the service callouts. For example, an entry to the US English localized name: {'en_US': 'updates the entity'} The description gets displayed in Corticon.js Studio.
  • extensionType (required) - SERVICE_CALLOUT - The extension type for a service callout in case sensitive text SERVICE_CALLOUT . If the extension type is not defined, the Corticon.js Studio will not see it as a service callout.
  • name(required) - Object, where the keys are locales (as strings) and the values are localized strings used for the name For example, the US English localized name. { 'en_US': 'updateData' }

Service Callout function implementation

To implement the service callout function, the function name must match the name defined in the service callout metadata definition. For example in the above metadata definition, the service callout function name is updateCargoEntity, so the function should also have that name. Here is an example of the service callout function that gets entities by type Cargo, and then updates the volume of the Cargo that has the container oversize:
function updateCargoEntity(corticonDataManager) {
const entities = corticonDataManager.getEntitiesByType('Cargo');
entities.forEach(entity => {
    if(entity['container'] === 'oversize') {
        //Update the attribute value to 50
        entity['volume'] = 50;
    }
});
}	

Configure runtime properties

You can add properties to the service callout so that, for example, when a REST service needs authentication, you can pass in credentials as part of the configuration that just sits in the wrapper, and then propagates the configuration to the service callout. These properties are outside the bundle, in the wrapper. That means that you do not need to redeploy the decision service every time you want to, say, change the log level from 0 to 1. These are overrides to the properties in a Ruleflow that are static service callout settings.

As configuration runtime properties, you can have your own encryption-decryption mechanisms. You can pass in your secret. You will need to have your decryption logic in your service callout function that can read these properties, and then use them as needed in your service callout function. Configuration runtime properties are not embedded in the decision service bundle JavaScript file.

Export actions

Specifies the type of export, and then an implementation you have defined. For example:
exports.updateCargoEntity = updateCargoEntity;	

The completed definition

The completed definition here is:
//Metadata
const updateData = {
    func: 'updateCargoEntity',
    type: 'ServiceCallout',
    description: {'en_US': 'updates the entity'},
    extensionType: 'SERVICE_CALLOUT',
    name: { 'en_US': 'updateData' }
};

//Service Callout Function Implementation
function updateCargoEntity(corticonDataManager) {
const entities = corticonDataManager.getEntitiesByType('Cargo');
entities.forEach(entity => {
    if(entity['container'] === 'oversize') {
        //Update the attribute value to 50
        entity['volume'] = 50;
    }
});
}	
//Config
const configuration = { logLevel: 0, "serviceCallout": { "prop1": "abc" , "prop2": 12 } };

//Export Actions
exports.updateCargoEntity = updateCargoEntity;