Search code examples
espercumulocity

Esper create expression - ReferenceError: \"function\" is not defined


Is there a problem with calling an expression inside another expression ? Cause when I do:

create expression int js:hexToBin(hex) [
  var bin = '';
  for (var i = 0; i <= hex.length - 1; i += 1) {
    bin += ('0000' + parseInt(hex.substr(i, 1), 16).toString(2)).slice(-4);
  };
  parseInt(bin, 2);
];

create expression int js:getTemperature(hex) [
  hexToBin(hex.substring(4, 6));
];

I got an error \"hexToBin\" is not defined. (getTemperature#2). But when I put all of the code in getTemperature it works properly.


Solution

  • As already said in the expression you are in JavaScript and it has no idea of esper.

    But an expression does not need to contain a single function. It is just some entry to a script so you can define multiple JavaScript functions within a single expression if you want to structure the code.