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
You can use this to set most datatype options, such as readonly and notnull, on individual questions, without having to create an explicit datatype. 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!
setproperty() really shines is that it allows for a very
dynamic experience: you can base a value on another answer in the same
setproperty(^details, 'visible', editedvalue(^checkbox_fill_in_details))
Which will hide the question called
details until the user chooses to show those details.
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: