JavaScript Execution

Variables available in JavaScript execution.


Variables available during execution of the JSScript's script:

  • session:Session. The user session

  • context:Context. The script context.

  • utils:Utils

  • input: Object. The input to the script


Example 1: Data Parsing

//The following JSScript converts a CSV string to a JSON//Get room configuration fetching apivar inputParts = input.split(",");
 
//Create an empty JSON and set the fieldsvar json = utils.createMap();
json.roomId = inputParts[0];
json.timestamp = utils.getDateFromAnyString(inputParts[1]);
json.temperature = utils.getNumber(inputParts[2]);
 
//Return the resultvar result = json;

Example 2: Condition check using API

//The following branch action checks if temperature of room exceeds configured threshold//Get room configuration fetching apivar getRoomConfig = session.getApi("getRoomConfig");
 
//Set room id to parameters
getRoomConfig.parameters.roomId = input.roomId;
 
//Get room configurationvar roomConfig = getRoomConfig.execute();
 
//Checks if temperature is greater than thresholdvar result = input.temperature > roomConfig.temperatureThreshold;