Skip to main content

Converting Calculated Columns

Informer 4 evaluated calculated columns with a JavaScript engine running inside Java. Informer 5 evaluates expressions in JavaScript on Node.js. When you import Informer 4 content, calculated columns come across as Java Calculated Field Flow Steps, and there are two ways to make them work: let Informer run them under a compatible Java engine, or convert the logic to native Informer 5 JavaScript.

Choose a Java compatibility mode during import

So imported calculated columns behave the way they did in Informer 4, the import asks for a Java Compatibility setting: the version of Java your legacy Informer server was running. Pick the matching engine:

  • Rhino (Java 7)
  • Nashorn (Java 8+)

If you are not sure which Java version your Informer 4 server used, check it on the legacy server:

  • Linux: open a terminal and run java -version. If the version is 1.7 or lower, choose Rhino; otherwise choose Nashorn.
  • Windows: open Control Panel, click Programs, select Java, then click About Java.
  • macOS: open System Preferences and select the Java icon.

Converting logic to Informer 5 JavaScript

You can also rewrite a calculated column as native Informer 5 JavaScript. Two Informer 4 patterns come up most often.

Java 8 arrays

If your Informer 4 server ran Java 8, array output needed extra steps to convert a JavaScript array into a Java array. For example, in Informer 4 on Java 8:

var xResult = new Array();
xResult[0] = 'First Value';
xResult[1] = 'Second Value';
var arrType = Java.type('java.lang.String[]');
Java.to(xResult, arrType);

In Informer 5, drop the Java conversion and return the array directly:

var xResult = new Array();
xResult[0] = 'First Value';
xResult[1] = 'Second Value';
xResult;

(If your Informer 4 server ran Java 7, array output was already handled this way and needs no change.)

SimpleDateFormat to Moment

Informer 4 often formatted dates with Java's SimpleDateFormat:

var sdf = new java.text.SimpleDateFormat('MM/dd');
sdf.format(dateAlias);

Informer 5 exposes Moment, which makes date formatting straightforward. The equivalent is:

moment(dateAlias).format('MM/DD');

Note that the format tokens differ: SimpleDateFormat uses dd for a two-digit day of the month, while Moment uses DD. See the Moment formatting documentation for the full set of tokens.