Skip to main content
Skip table of contents

Form scripts

It is possible to write small scripts that update the form values. The script is run whenever you change a field in the form whilst completing the form. This is a functionality that has to be enabled by Microbizz, and currently it only works when completing a question form in the browser, not in the app. For details about script see this.

When you setup the form you can specify if a field should be updateable from the script:

Editing the script

The script is edited in the SCRIPT tab, where you can also try out the form:

When the script is run a variable named a is set up to hold all the current values from the question form.

You may update the variable, and the question form will then ne updated with the new values. To update the field with ID 5 you write a new value to a[5]. You access the current values the same way: a[3] will return the current value of the field with ID 3. You can see the ID of a field by holding the mouse over the field, the ID will appear in the tooltip.

Field types

You can update most field types, except for files, pictures and signatures, but including the static text fields.

Notice that when you set the value for a radio / several of many / one-of-many field, you should not specify the text that is displayed to the user, but instead specify the underlying value used by Microbizz. F.ex. for the field below you might specify

a[7] = 2

instead of

a[7] = "Ringo"

For multi fields you have to specify a list of values to select, eg.: a[8] = [2,5,1] .

Bugs

There is a known bug which complicates reading values from “several of many” fields. The bug is difficult to fix so you will have to work around the problem.

When the script is executed for a form that includes a “several of many” field, the value for the field is an array if one or more options have been selected by the user, eg. a[9] may be set to [1,2] if the second and third options are selected (first option is number 0!). There are a bunch of useful functions for examining / manipulating this array, like index() and slice() but these do not work as long as you access the array directly via a[9]. Instead you must copy the array to a new variable and then you can use index() or slice().

Example

PY
// doesn't work
if a[9].index(1) >= 0
  a[10] = "You have selected item 1"

// works
a9 = a[9]
if isarray(a9) && a9.index(1) >= 0
  a[10] = "You have selected item 1"

Feedback

The script may report back to the user by using the function echo().

F.ex.:

echo("Remember to inform the accounting department")

This text will be shown to the user just like many other informations:

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.