Powered by Zoomin Software. For more details please contactZoomin

Corticon.js Extensions

Use functions defined in other JavaScript files

Use functions defined in other JavaScript files

  • Last Updated: October 26, 2026
  • 1 minute read
    • Corticon.js
    • Version 2.4
    • Documentation

You can use a library or functions defined in supporting JavaScript files by creating a file that defines the function, and then using the function from a require statement.

Example of a utility function

CODE: CallToSeparateLibrary/Util.js

This example determines the appropriate greeting based on the time of day.

function getPeriodOfDayFromCurrentTime() {
  const hour = new Date().getHours();
  let postfix = 'night';
  if (hour < 12)
    postfix = "morning";
  else if (hour < 18)
    postfix = "afternoon";
  else if (hour < 21)
    postfix = "evening";

  return postfix;
}

function notExposedPublicly() {
  ...
}

module.exports = {
  getPeriodOfDayFromCurrentTime
};

The last line exposes the function publicly.

Example of referencing the utility function

With the function defined, the require call brings the function into the service callout, and then exports the result, as follows:

CODE: HelloWorldServiceCallout.js

const utility = require('./Util');

const hello = {
  func: 'sayHelloFct',
  type: 'ServiceCallout',
  description: {
    en_US: 'This function writes a greeting message into the Hello entity'
  },
  extensionType: 'SERVICE_CALLOUT',
  name: {
    en_US: 'hello'
  }
};

function sayHelloFct (
  corticonDataManager
) {
  const postfix = utility.getPeriodOfDayFromCurrentTime();
  const entities = corticonDataManager.getEntitiesByType('Hello');
  entities.forEach(
    entity => {
      entity.message = 'Hello World from SCO.  I wish you a good ' + postfix;
    }
  );
}

exports.sayHelloFct = sayHelloFct;

Note: Only Node module usage is supported where you can use require and module.exports. Modules written with ES6 import/export are not supported.

Alert