General examples

Input

Set input

The input of a call to a service or a command is set as followed:

// Initialize a variable to the entity type of the input to the service 
const inputToService = this.factory.entity.nsacrnm.ServiceIdentifier_Input();

// Set the values of the input properties
inputToService.property1 = value1;
inputToService.property2 = value2;

// Call the service with the given input
await this.services.nsacrnm.ServiceIdentifier(inputToService);


// Initialize a variable to the entity type of the input to the command
const inputToCommand = this.factory.entity.nsacrnm.CommandIdentifier_Input();

// Set the values of the input properties
inputToCommand.property1 = value1;
inputToCommand.property2 = value2;

// Call a command with the given input

Input as list

The input of a call to a service or a command is set as followed:

// create two service input objects 
const input1 = this.factory.entity.nsacrnm.ServiceIdentifier_Input();
const input2 = this.factory.entity.nsacrnm.ServiceIdentifier_Input();
const inputToService = [input1, input2];

// call the service passing the needed array
await this.factory.service.nsacrnm.ServiceIdentifier(inputToService);

// access service input list
const val1 = this.input[0];
const val2 = this.input[1];

Output

Set output

The output of a service is set as follows:

// Initialize a variable to the entity type of the output of the service
const output = this.factory.entity.nsacrnm.ServiceIdentifier_Output();

// Set the values of the output properties
output.property1 = value1;
output.property2 = value2;

Output as list

The output (as a list) of a service is set as follows:

// create two service output objects 
const output1 = this.factory.entity.nsacrnm.ServiceIdentifier_Output();
const output2 = this.factory.entity.nsacrnm.ServiceIdentifier_Output();

// set service to return list
this.output.push(output1);
this.output.push(output2);

// call a service and get its output
Const output = await this.factory.service.nsacrnm.ServiceIdentifier(inputToService);

// access the values of the output properties
const val1 = output[0].property1;
const val2 = output[1].property2;

Root entities

Reference root entities

To reference a root entity use the following structure:

// Initiate the reference and give as the id of the instance that is meant to be referenced
const reference = this.factory.reference.nsacrnm.RootEntityIdentifier(id);

// Load the specific instance
const rootEntityInstance = await reference.load();

// Now one can access the properties and their values (read-only) of the specific instance
rootEntityInstance.property1;
rootEntityInstance.property2;

// Now one can access the instance command that will manipulate the specific instance
rootEntityInstance.instanceCommandIdentifier();

List of root entity references

To use a list of root entity references as a property use the following structure:

// Initialize empty list
entityIdentifier.propertyIdentifier = [];

// Create new root entity references
const reference1 = this.factory.reference.nsacrnm.RootEntityIdentifier(id1);
const reference2 = this.factory.reference.nsacrnm.RootEntityIdentifier(id2);

entityIdentifier.propertyIdentifier.push(reference1);
entityIdentifier.propertyIdentifier.push(reference2);

Local entities

Reference local entities

To use a local entity as a property use the following structure:

// Create a service input entity
const inputToService = this.factory.entity.nsacrnm.ServiceIdentifier_Input();

// Create local entity object
const localEntity1 = this.factory.entity.nsacrnm.EntityIdentifier();

// Set entity properties
localEntity1.propertyIdentifier = 'some property value';

// Set local entity value as a service property value
inputToService.propertyIdentifier = localEntity1;
List of local entity references
To use a list of local entities as a property use the following structure:

// Create a service input entity
const inputToService = this.factory.entity.nsacrnm.ServiceIdentifier_Input();

// Initialize service property (of type local entity list) to empty list
inputToService.propertyIdentifier = [];

// Create local entity objects
const localEntity1 = this.factory.entity.nsacrnm.EntityIdentifier();
const localEntity2 = this.factory.entity.nsacrnm.EntityIdentifier();

// Set entity properties
localEntity1.propertyIdentifier = 'some property value';
localEntity2.propertyIdentifier = 'some other property value';


// Push local entities to the property list
inputToService.propertyIdentifier.push(localEntity1);
inputToService.propertyIdentifier.push(localEntity2);

Reuse types and classes from Solution Framework

Use Solution Framework logger

import { Logger } from 'acronym_sdk';

public async execute(): Promise<void> {

  // call helper function with logger
  myUtil(this.util.log);
}

/**
 * utility function that needs a logger
 */
function myUtil(logger: Logger) {
  // use logger
  logger.info('myinfo');
}

Use CurrencyValue

import { CurrencyValue } from 'acronym_sdk';

public async execute(): Promise<void> {

  // call helper function with currency value from instance
  const newVal = setCurrencyCode(this.instance.myCurrProp);
}

/**
 * utility function that sets the currency of a currency value and returns the currency
 */
function setCurrencyCode(currencyVal: CurrencyValue, code: string): CurrencyValue {
  currencyVal.currency = code;
  return currencyVal;
}

Use schemas and entities

import { schemas, entities } from 'acronym_sdk';

public convertSchemaToEntity(schema: schemas.ns2.Schema1): entities.ns1.Entity1 {
  // create a new entity and set schema values
  const e = this.factory.entity.ns1.Entity1();
  e.value1 = schema.value1;

  return e;
}

public convertEntityToSchema(entity: entities.ns1.Entity1): schemas.ns2.Schema1 {
  // create a new schema and set entity values
  const s = this.factory.schema.ns2.Schema1();
  s.value1 = entity.value1;

  return s;
}