Skip to content

A Smart Script shows an error or an empty value

Troubleshooting8 minExpert

Smart Script is JavaScript that Beezr runs after it swaps your tokens for values. The swap is plain text replacement, and that explains most surprises. Read the symptom you have.

The field or card shows my script instead of a value

Section titled “The field or card shows my script instead of a value”

Cause. The script has an error, so the field shows the script’s own text instead of a result.

Check. Copy the shown text into the editor and check spelling, brackets and function names. Common slips: a top-level return, an arrow function, let or const.

Fix. Smart Script runs on the Nashorn engine of Java 8, which reads the older ES5 style. Use var and function. In a dashboard metric, make the last expression the result and do not write return at the top level. In a Default value, the same rule applies. Use Run test in the dashboard builder to see the real error.

Arithmetic gives the wrong number, or the numbers join as text

Section titled “Arithmetic gives the wrong number, or the numbers join as text”

Cause. A token for a Text, Text area or Long field is replaced with a quoted string, such as '12'. Adding two of them joins them: '12' + '3' is '123'.

Fix. Wrap each value in parseInt(...) for whole numbers or parseFloat(...) for decimals, with no quotes: parseFloat($cm_orders_base$.$subtotal$) * 1.14. Always use the full $table$.$field$ token, and insert it with Insert data so the table name is right. Never write a bare $field$.

Values from FunctionManager calls also arrive as strings. Convert them before you add, compare or round: parseFloat(FunctionManager.evaluateSumFunction("amount", "cm_invoices_base", "")).

The result is NaN, or the script has a syntax error when a field is empty

Section titled “The result is NaN, or the script has a syntax error when a field is empty”

Cause. An empty number or date field is replaced with nothing. parseFloat( ) * 2 becomes NaN, and 5 + does not parse at all. A Text field that is empty arrives as the word null inside quotes, which is a real string, not a missing value.

Fix. Give numbers a fallback: parseFloat($cm_orders_base$.$discount$) || 0. Test text against 'null' and the empty string, or add a Decision before the step that checks the field is not empty.

A date comes out wrong or the date maths gives NaN

Section titled “A date comes out wrong or the date maths gives NaN”

Cause. A date token arrives as text in the day, month, year order, with the time if it has one. JavaScript’s new Date('13/02/2026') reads the first number as the month, so day 13 and later fail, and earlier days swap day and month.

Fix. Split the text yourself: var p = text.split('/'), then new Date(parseInt(p[2], 10), parseInt(p[1], 10) - 1, parseInt(p[0], 10)). Write dates back as yyyy-MM-dd, which the save accepts.

Cause. There are three quiet ways to get an empty result.

  • The token names a module or a field that is not in the data the script can see. In a workflow, load the record before using its module tokens.
  • The script’s last expression has no value. A script that ends with an assignment, or with a FunctionManager call that returns nothing, gives nothing.
  • A token on a list reads the list’s first record, unless you are inside a Loop over it.

Fix. Print the pieces. End the script with the variable you want to see, for example String(total). In a workflow, check the name you gave Load data, and use it as $list_name$.$field$.

A dashboard card breaks when there is no data

Section titled “A dashboard card breaks when there is no data”

Cause. FunctionManager.loadRecordsByClause and its relatives return a list, and the list can be null or empty. A field map entry can be missing too. Calling .size() or reading a field on null throws.

Fix. Guard first.

var rows = FunctionManager.loadRecordsByClause("cm_invoices_base", "where status = 3");
var total = 0;
if (rows != null) {
for (var i = 0; i < rows.size(); i++) {
var f = rows.get(i).getFieldValueMap().get("gross_amount");
if (f != null) { total += parseFloat(f.getCurrentValue()) || 0; }
}
}
String(total);

getCurrentValue() returns text, hence parseFloat. For counts and sums, evaluateCount and evaluateSumFunction do the loop for you. An empty script on a card reports The script is empty. Write an expression that returns a value.

How do I confirm a Custom function did its work?

Section titled “How do I confirm a Custom function did its work?”

Check. A Custom function does its work by running your script. Calls such as createRecords return true or false.

Fix. Confirm the result inside the workflow. After the step, add Load data for what it should have created, then a Decision on the list with has no records, and a Terminate set to Failed on the empty path. In the script, you can also test the value that createRecords returns. See Custom function.

Cause. The rules of Load data become a query clause, and a step with no rules loads nothing.

Fix. Add the rule and name the list. For long lists, turn on Process in pages on the Loop.