Skip to main content

Scripting

Overview

Scripting lets you compute a final value for a Profile question using code instead of a manual selection.

Use this when you need advanced logic (for example: score computation, segmentation, status labels, or dynamic classification based on previous answers).

Prerequisites

To use scripting, configure your question with all of the following:

  • Question type: Profile question
  • Mode: Automatic
  • Automatic type: Scripting (Compute a value with a script)

When this setup is enabled, a dedicated text area appears (editor-like input) where you can write the script that calculates the respondent's final value.

What your script can reference

Your script can use values from previous questions by reference:

  • Q1
  • Q2.I2
  • and similar references depending on question structure

Supported source question families include:

  • Profile questions
  • Item batteries
  • Hotspot questions
  • Open questions

JexlScript syntax basics

Scripting is based on JexlScript. If you are familiar with JavaScript-like control flow, you will quickly recognize the syntax.

Key syntax rules:

  • End each instruction with ;
  • Use var to declare variables
  • Use if (...) { ... } for conditions
  • Use else { ... } for alternative logic
  • Use return ...; to output the final computed value
  • Use ==, >, <, >=, <=, &&, || for comparisons and logical tests

Example script

var genre = text(Q1);
var age = entier(Q2);

var value = "N/A";

if (genre == "Homme" || genre == "Femme") {
value = genre;

if (age > 45) {
value = value + " hors cible";
} else {
value = value + " dans la cible";
}
}

return value;

What this example does:

  • Reads gender from Q1 as text
  • Reads age from Q2 as an integer
  • Builds a label only for expected gender values
  • Returns N/A when no valid classification can be computed

Useful functions

Commonly used helper functions include:

  • round(...)
  • max(...)
  • number(...)
  • text(...)
  • exponential(...)

Depending on your project version and configuration, additional helper functions may be available.

Additional examples

Numeric score with rounding

var scoreA = number(Q3.I1);
var scoreB = number(Q3.I2);

var total = scoreA + scoreB;
var avg = round(total / 2);

return avg;

Keep highest value from multiple inputs

var v1 = number(Q4);
var v2 = number(Q5);
var v3 = number(Q6);

var highest = max(v1, v2, v3);
return highest;

Best practices

  • Initialize a default fallback value first (for example "N/A")
  • Convert values explicitly (text(...), number(...)) before comparisons
  • Keep scripts short and readable
  • Test edge cases (empty answers, unexpected values, missing responses)
  • Always verify that the script returns a value in all branches