getLogger() Returns a handle to the logger. It provides a mechanism to log trace or errors into the logfile based on the decision service configuration
getConfiguration() Returns a reference to the service callout properties passed in the decision service overall configuration
getAllEntities() Returns all the entities in the working memory.
getEntityTypes() Returns all the entity types in the working memory.
getEntitiesByType() Takes the Entity type as a parameter, and then returns all the entities of the type in the working memory.
createEntity(<entityType>) Takes a String defining the entity vocabulary type. Creates an entity with the defined entity type at the root and a unique identifier. Returns the newly created Entity.
createEntity(<entityType>,{initializers}) Takes a String defining the entity vocabulary type. The function also accepts an initializer JSON object to set the attributes of the entity. Creates a new entity with the defined entity type at the root. Returns the newly created Entity.
removeEntity(<entityObject>) Removes the entity from the working memory.
getOperator() Accesses a decimal, dateTime or date operator. See Use APIs to update attributes sections:
addAssociation(entityObject1, entityObject2, roleName) Adds an association of the element Entity2 with Entity1, provided such an association is allowed by the Vocabulary.
setAssociation(entityObject1, entityObject2, roleName) Replaces any existing elements of Entity1.roleName.
removeAssociation(entityObject1, entityObject2, roleName) Removes the element Entity2 from Entity1.roleName, provided such element is currently associated.
addEntitiesAndAssociations(entityType, payload) Adds entities and associations as top level entities.
addAssociationsToEntity(parentEntity, rolename, payload) Adds nested associations to existing entities in the working memory.

EXAMPLES

getLogger() example

let logger;

function <serviceCalloutFunctionName> (corticonDataManager) {
  logger = corticonDataManager.getLogger();
  logger.logDebug('some text') // Will only be logged when configuration = { logLevel: 1 };
  logger.logError('We encountered error xyz') // Will be logged independently of logLevel.
}	

getConfiguration() example

const configuration = { logLevel: 0,
	"serviceCallout": 
		{ "prop1": "abc"
		, "prop2": 12 
		} 
	};
The SCO will be passed the object literal: { "prop1": "abc", "prop2": 12 }
Note: These runtime properties are not embedded in a decision service bundle JavaScript file.

getAllEntities() example

function <serviceCalloutFunctionName> (corticonDataManager) {
  const entities = corticonDataManager.getAllEntities();
  //You can then use the entities returned to either modify the data/update the attributes
}	

getEntityTypes() example

function <serviceCalloutFunctionName> (corticonDataManager) {
  const entityTypes = corticonDataManager.getEntityTypes(); 
}	

You can then use the entity types to get all the entities of a particular type and then update or modify the data as needed.

getEntitiesByType (<entityType>) example

Takes the Entity type as a parameter, and then returns all the entities of the type in the working memory. For example:
function <serviceCalloutFunctionName> (corticonDataManager) {
  const cargoEntities = corticonDataManager.getEntitiesByType('Cargo');
  //This will return all the entities of type Cargo in the working memory
} 	

createEntity(<entityType>) example

Another way to create an Entity is to just specify the entityType. This will create an entity with the defined entity type and a unique identifier.

function <serviceCalloutFunctionName> (corticonDataManager) {
	const entityAircraft = corticonDataManager.createEntity('Aircraft'); 
			//Creates a new entity aircraft, with a unique identifier. 
			//This new entity is  also added to the root of the JSON.
			} 

You can then set the attributes of this new entity:

function <serviceCalloutFunctionName> (corticonDataManager) {
	const entityAircraft = corticonDataManager.createEntity('Aircraft');
		//Creates a new entity aircraft, with a unique identifier. 
		//This new entity is also added to the root of the JSON.  
	entityAircraft['aircraftType'] = '737Boeing'; 
	} 

For more information, see Use APIs to update attributes

createEntity(<entityType>, {initializers}) example

Create an new entity at the root. Takes a String defining the entity vocabulary type. The function creates the entity in the JSON document with a unique identifier. The function also accepts an intitalizer JSON object to set the attributes of the entity. The function returns the newly created Entity.

For example, to initialize an Entity of type Aircraft, and also set the attribute aircraftType to '737Boeing'

function <serviceCalloutFunctionName> (corticonDataManager) {
	const entityAircraft = corticonDataManager.createEntity('Aircraft',{'aircraftType':"737Boeing"}); 
		// Creates a new entity aircraft, with a unique identifier and sets the attribute aircraftType 
		// This new entity is also added to the root of the JSON 
} 

removeEntity(<entityObject>) example

Removes the entity from the working memory. For example:
function <serviceCalloutFunctionName> (corticonDataManager) {
  
  const entities = corticonDataManager.getEntitiesByType('Cargo');
  let entityToRemove;
  entities.forEach(entity => {
      if(entity['container'] === 'oversize') {
        entityToRemove = entity;
      }
  });
  corticonDataManager.removeEntity(entityToRemove);
}