The formulas of scales and grids are written in text boxes, but to write a multi-line script and immediately check what it calculates there are two dedicated tools. This article explains how to open them and how to read them. For the syntax (variables, if, return, prev, carry) see Expressions. It is for whoever sets up scales and grids in Settings → Prices lists, products and services.
1. Two tools, one way of working
Tool | Where it opens | What it is handy for |
|---|---|---|
Try live | In the grid's (or scale's) form, under each expression box, next to Write with Marin.AI. | Trying a formula you are writing, without leaving the form. |
Edit & test | On the grid's page, Configuration tab, Expressions & formulas box: a button next to each formula. On a scale's page: next to the Value expression. | Writing and adjusting a long script, full page, and saving it from there. |
They do the same job: on the left (or at the top) the code, the Sample inputs to fill in, and the Result, which recalculates by itself a moment after you stop typing.
2. The Try live window
Open the grid's form (Update price grid) and press Try live under the box that interests you.
The Try this expression live window opens, with the Sample inputs at the top, then the Expression / script box, then the Result.
Fill in the test data and edit the code: the result updates at every change.
If you like the code, press Use this expression: the text is copied into the form's box. The changes made in the window pass to the form only when you press this button; then save the grid as usual.
3. The Edit & test page
It opens a page titled with the grid's name (for a scale, the field's name) and, below, the name of the field you are editing: Generation expression, Cost formula, Applicability, Quantity or Unit price. A grey line reminds you which variables are allowed in that box.
On the left the large editor, with line numbers. The Save and Cancel buttons are below. At the top right, Back to price grid leaves the page without saving.
On the right the Sample inputs and the Result.
When you press Save the formula is checked. If it is wrong you get a message (“Invalid expression — …”) and stay on the page. If it is correct “Expression saved.” appears and you return to the grid's page. If you empty the box and save, the formula is removed.
Here too the rules of each box apply:
GRID()is only accepted in generation formulas, and two formulas that expect each other's result (the rate readingcell.costwhile the cost readscell.value) are refused.
After saving you must press Generate on the grid for the matrix to use the new formula.
4. What you see while you write
Suggestions. While you write (or by pressing Ctrl-Space) the editor suggests the variables allowed in that box, the functions, this grid's parameters and variants (
params.…,variant.…) and, in the generation formula, thecarry.…of the variables you have assigned.Result. The value calculated by the script. If the formula produces no value you see “(no value produced)”.
Variables. If the script assigns variables, under the result a Variable, Value, Line table appears with the value of each assignment: it helps you understand where a calculation takes an unexpected path.
Errors. If the code is incomplete or wrong, the error message appears instead of the result and the line that causes it is highlighted in red.
5. The sample inputs
The Sample inputs change with the box you are testing:
Box | What data it asks for |
|---|---|
Generation expression, Cost formula | Those of the cell: |
Applicability, Quantity, Unit price | Those of the boat and the contract: |
A scale's Value expression |
|
In the cell.value and cell.cost fields, leave a box empty to test the “value not yet known” case.
Testing formulas band by band. In the real grid, the generation formula calculates one band at a time and carries with it the result of the previous one. In the test there is no band before: to see how the script behaves at the third band, write yourself the values it would have received, that is prev (the previous band's result) and, in the carry.…, the name and value of each variable of the previous band. For the first band leave prev at 0 and the carry empty.
6. With Write with Marin.AI
The Write with Marin.AI button is in the grid's form, under each box, not on the Edit & test page. You can describe the rule in words, even for a multi-line script, and then test the result with Try live before saving: see Writing a formula with Marin.AI.
If something goes wrong
The result does not appear. Check that the test data contains all the values the formula reads: an empty variable gives an error or no value.
GRID()gives no result. The test does not know the other grids: to see the value press Generate on the grid (see Building a grid from another one with GRID()).Saving is refused. The message says which variable is not allowed in that box or where the error is: correct it and save again.
See also: Expressions, Writing a formula with Marin.AI, Price grids, Price scales and Testing a grid.

