Before reading this section, we suggest you take a look at getting started with formulas first. In general, it is useful to do the guided tour before you start with the other guides.
Actions are a different type of formula.
You can add them in almost the same way, via
Actions > Action.
The one big difference between formulas and actions is that actions do not return a value.
For example, consider the formula
now() gives the user the current date, or, it returns the current date.
An action is different: it does something, and that’s it.
The easiest example is the
This action sets the initial value to a variable, but when the user edits it, the initial value is discarded.
You can do the same with questions by entering something in the default-field.
initvar() might look like this:
initvar(^name, 'John') initvar(^gender, 'Female')
You can also ‘reset’ the value of an initvar.
This is done with a similar actions,
Another really useful action is
This versatile action can assign all kinds of properties to questions, yet it never returns any value. Consider this example:
setproperty(^name, maxlength, 10)
This will change the maximum length of the user’s answer to the question name to 10. Yet it does not return any value! You can use this for several different goals, such as setting readonly and not null properties to questions. You can also edit the precision of numbers, and more.
It is possible to give nodes and actions metadata. Metadata can be used by the presentation layer to change certain things. For example, you can change the text on the ‘Next’ and ‘Previous’ buttons. In order to add metadata, you can use the following action:
To remove metadata use
'' as a value. This causes nothing to be sent for the key:
Aside from influencing the presentation layer, metadata can also be used by other applications. This might be relevant when Berkeley Studio models are used in another application.
You can change the language of a model with an action as well.
This is useful if you use a lot of functions that need a language.
datetext() usually both need a language parameter.
With the language set, they will take that language automatically!
You can set the language with: