Smart Script: the language of Beezr
Smart Script is how you tell Beezr to work something out: a default value, a check before save, a filter for a list of records, a number on a dashboard. It is JavaScript with two additions, tokens that bring in your data, and a helper library called FunctionManagerFunctionManagerThe Smart Script helper library exposed by the interpreter.Open glossary ↗ that reads and writes records. If you can read a few lines of JavaScript, you can read any Smart Script.
The engine behind Smart Script is Beezl.
Where does a Smart Script run?
Section titled “Where does a Smart Script run?”Anywhere a box says Smart Script, or hints at a script. These are the places we checked in the code.
| Place | What the script gives back | Where you write it |
|---|---|---|
| Default value | The starting value of a new record’s field | Fields, field editor, Default value |
| Smart field | The field’s value, worked out when the record is shown | Fields, Script |
| Rule Book | true to pass, anything else to fail, before save | Forms, Form rules, Rule Book |
| Disabled If and Visible If | true or false for a form button | Forms, button component |
| Form parameters and button parameters | The value that prefills another form | Forms, parameters |
| Custom HTML component | The HTML the form shows | Forms, Custom HTML |
| Load data step | A WHERE filter for the records to load | Which records?, Smart Script tab |
| Record manager, Approval task, Send email, Loop, JSON parser | A value for a field, a person, a recipient, a count or a payload | The step’s value boxes |
| Custom function step | Nothing. The script runs for what it does | Smart Script box |
| Dashboard Metric | The number or text the block shows | Value |
| Dashboard Custom HTML | One value per ${variable} | Variables tab |
| Data quality rule of type SCRIPT | true or false | Data tools |
WHERE clause.cm_customers.tier.The Decision step is different: it builds its conditions from a field, an operator and a value.
How does Beezr read a script?
Section titled “How does Beezr read a script?”Four things happen, in this order.
- Tokens become values
- Script runs as JavaScript
- Last expression is the result
- Result becomes text
- Tokens become values. Before anything runs, Beezr replaces every
$table$.$field$with the data it stands for. Text arrives in quotes, numbers arrive as they are. Tokens and placeholders lists every kind. - The script runs. It runs as JavaScript, with
FunctionManagerready to use. - The last expression is the result. There is no
return. The scripttotal;gives back whatevertotalholds. - The result becomes text.
truebecomes"true",42becomes"42". The place that asked for the value reads the text.
Check a new script with Run test where the editor offers it. If the result is your own script text, a name in it is misspelled.
Which mistakes catch everyone?
Section titled “Which mistakes catch everyone?”Four rules cover most broken scripts.
getCurrentValue()returns a string. Even for numbers and dates. UseparseInt(value, 10)orparseFloat(value)before you add, and parse dates before you compare them.loadRecordsByClausereturnsnullwhen nothing matches, not an empty list. Check it before you loop.- Loop with
.forEach. The lists are Java lists, and.forEachis how you go through them. - Write
WHEREclauses with the fulltable.fieldname, such ascm_purchase_orders.status. Text values need quotes. Filter lookup fields by their id, and useresolveLookupIdValuewhen you need the text people see.
Dashboard scripts have one more: they end with an expression, with no return. Script a dashboard metric shows it in a finished script.
For evaluateCount, evaluateSumFunction and evaluateAverageFunction, write the clause exactly as it must run, starting with WHERE.
What do I read next?
Section titled “What do I read next?”Write three small scripts in Write your first Smart Scripts. Keep Tokens and placeholders open next to it. Every function FunctionManager offers is on Smart Script functions.
Check yourself
What's next
Last checked