getAssociationsForEntity(parentEntity, rolename)

To access the data in the working memory you can use this API. The entity can be at any level in the input tree. This api takes two parameters, the parentEntity and the rolename. The parentEntity is the entity in the working memory that you want to query. The rolename is the association you want to fetch (as defined in the vocabulary). The API returns a JSON Array. It will bring all the associations for the rolename and also nested associations.

Let say we want to get a flightPlan association to a particular Cargo. 
//Metadata for the Service Callout
const getFlightPlanAssociationCargo = {
    func: 'getFlightPlanAssociationCargoFct',
    type: 'ServiceCallout',
    description: {'en_US': 'This function is used to get flight plans for the cargo'},
    extensionType: 'SERVICE_CALLOUT',
    name: {'en_US': 'getFlightPlanAssociationCargo'}
};
//Service Callout Function
async function getFlightPlanAssociationCargoFct(corticonDataManager) {
	const logger = corticonDataManager.getLogger();
try {
		//This API gets the Cargo entities in working memory
		const entities = corticonDataManager.getEntitiesByType('Cargo');
		/* Logic to determine the Cargo, the parent entity which will be used.
		   In this example we are using volume and if the volume of the Cargo
		   equals 10 then we are going to get the flight plan 
		   The logic determines the parent entity and that parent entity in passed
		   to the API below
		*/
		let entityParent;
		for (let entity of entities) {
			if(entity['volume'] === 10) {
				entityParent = entity; //Determines the parent Entity to be used.
				break;
			}
		}
		/* This call then passes in the parent entity, the role name < FlightPlan> as defined
		in the vocabulary. If there are no errors, json is returned from the API
		In this case it will have all the flight Plans which are associated with the Cargo.
		If the FlightPlan has another association attached to it it will be returned as well. */
		const jsonReturned = corticonDataManager.getAssociationsForEntity(entityParent, "FlightPlan");
		logger.logDebug(`*** Data retrieved`+JSON.stringify(jsonReturned));
		//Write the JSON to a file
		const fs = require('fs');
		fs.writeFileSync('Output.json', JSON.stringify(jsonReturned, null, 2));
	}
	catch ( e ) {
		logger.logError(`*** Error retrieving data : ${e}`);
	}  
}	
//Exports
exports.getFlightPlanAssociationCargoFct = getFlightPlanAssociationCargoFct;