Most Forsta Plus surveys contain a quantity of script code. Scripts are used:
- In conditions, for controlling the flow through the questionnaire (skipping logic) and controlling whether or not questions are to be displayed (question masks and column masks (in 3D grids)).
- For filtering the lists displayed in questions and the iterations in loops based on previous answers (code and scale masks).
- In form elements for text substitution (response piping).
- For custom validation of user input.
- In general-purpose code contained in script nodes.
Forsta Plus can use both Microsoft’s JScript .NET scripting engine and JavaScript to evaluate all questionnaire expressions and to execute scripts. The run-time environment of the interview engine supplies a number of functions and objects that provide references to and let you manipulate survey variables. This documentation covers some of the fundamentals of JScript.NET and JavaScript, and the functions and objects provided by Forsta Plus.
JScript.NET is JScript extended with features of class-based languages. All script code in Forsta Plus will however be wrapped as functions inside a class. This means that you cannot define your own classes in Forsta Plus scripts.
Forsta Plus is gradually moving away from JScript and the use of JScript is disabled by default for new users. We encourage all existing users to consider using JavaScript instead (JavaScript is the only supported language for the AskMe or CAPI Apps on mobile devices). However, as both scripting languages are still in use, we have given examples in both JScript and JavaScript where there are differences in the code examples presented. To closely align the JavaScipt examples with the outgoing JScript, JavaScript examples are shown using pre-ES6 syntax standard. You may wish to take advantage of the supported ES6 (and later) syntax standards however.
Examples of scripting written in JScript is presented in a code block with a light orange background, and titled as a JScript example, as shown below.
var s = new Set()
f('multiQid')['code'].set(1)Examples of scripting written in JavaScript is presented in a code block with a light green background, and titled as a JavaScript example, as shown below.
var s = set()
f('multiQid').item('code').set(1)Any code that is the same between both scripting languages, is presented in a light grey background, as shown below.
f("q1").inc("1 ")
Note: In order to support JavaScript, you must ensure your survey has the Use JavaScript scripting engine option turned on. This option can be found in the Survey Design tab > Settings > Options panel, when editing a survey.
This documentation only covers server-side programming, i.e. scripts that are running on the server. It does not consider client-side scripts (scripts that run on the respondent's browser – typically written in JavaScript), so for example scripting of HTML elements is outside the scope of this documentation.