Overview
OptOutRespondent(optOutType) is a JavaScript‐only function used to mark a respondent as opted out.
Depending on the specified optOutType, the respondent will be opted out from a specific project, an entire company’s surveys, or from a panel.
Notes
This function only works in the JavaScript engine; it does not work in JScript.
The respondent’s record must contain a valid
emailvalue for the opt‐out to succeed.
Usage
OptOutRespondent(optOutType);
optOutType: A string that defines the scope of the opt‐out.
Possible Values
PROJECT: Opts the respondent out of the current survey (project).
COMPANY: Opts the respondent out of all surveys under the same company.
PANEL: Opts the respondent out of the panel associated with this survey, as well as all surveys attached to that panel.
PANEL to work.Example 1 – Simple Opt‐Out by Type
// Capture the user’s choice for opt-out (PROJECT, COMPANY, or PANEL)
let optOutType = f('optOutTypeSelector').get();
// Call the function
OptOutRespondent(optOutType);
In this example, f('optOutTypeSelector') could be a single‐select question on the survey page that allows the respondent to choose the level of opt‐out.
Example 2 – Ensuring email Is Defined
// Get the respondent's email from a survey field or respondent list
const respondentEmail = GetRespondentValue('email');
// The respondent's email must be defined for the opt-out to work
if (!respondentEmail) {
// If no email is found, do nothing or handle the error
return;
}
// Determine optOutType from a question or logic
let optOutType = '';
switch (f('optOutTypeSelector').get()) {
case '1':
optOutType = 'PROJECT';
break;
case '2':
optOutType = 'COMPANY';
break;
case '3':
optOutType = 'PANEL';
break;
}
// Perform the opt-out
OptOutRespondent(optOutType);
Key points Demonstrated in this Example:
We first verify that an email exists by retrieving it via
GetRespondentValue('email').We use a switch statement to convert a numeric or coded response to a text value for
optOutType.We then call
OptOutRespondent(optOutType)to finalize the opt‐out.
Troubleshooting
Function Doesn’t Fire / No Effect
Ensure you are using the JavaScript engine. This function will not work in JScript.
Confirm the email column in your respondent data contains a valid value. If email is blank or missing, the respondent cannot be opted out.
Panel‐Based Opt‐Out Not Working
Verify the survey is attached to a panel.
Ensure the respondent is in that panel.
Legacy (JScript) Alternative
For JScript‐based surveys, the older approach (e.g., Extension("Email Opt-Out")) may still be used.