Actions

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.

adding a new action
adding a new action

The one big difference between formulas and actions is that actions do not return a value. For example, consider the formula now(). The function now() gives the user the current date, or, it returns the current date. An action is different: it does something, and that’s it.

Initializing variables

The easiest example is the initvar() action. 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. An 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, resetinitvar():

resetinitvar(^name)

Setting properties

Another really useful action is setproperty(). 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.

Metadata

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:

setmetadata('key', 'value')

To remove metadata use '' as a value. This causes nothing to be sent for the key:

setmetadata('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.

Language

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. For example, inwords() or datetext() usually both need a language parameter. With the language set, they will take that language automatically! You can set the language with:

setlanguage('en')
setlanguage('nl')