The listUnique
function iterates over a list and a field reference, checking whether each row-question in a table contains a distinct response. This function is particularly helpful for verifying that text inputs and autoothers do not contain identical responses.
Tip! Not sure which list function is best suited for your needs? Review all list functions here.
Syntax
In its most basic form, listUnique
accepts two inputs: a list name with optional inclusion/exclusions, and a field reference constructed with an iterator.
The syntax examples below use listUnique
to return the result of the evaluated statement, and show how to use listUnique
to include or exclude options. The statement is evaluated and returns either a '1' for "Yes, the items are unique" or a '0' for "No, the items are not unique." If duplicate responses are found, an error message will be shown.
#Basic format listUnique(LISTNAME; Field reference with [id]) #Inclusion syntax to limit options from list listUnique(LISTNAME [IDs to include]; Field reference with [id]) #Exclusion syntax to limit options from list listUnique(LISTNAME -[IDs to exclude]; Field reference with [id])
Examples
Unique text entries
This basic example references the series
function as the list name, and uses [id]
as the iterator, which pulls in each option ID established in the series. Each field reference constructed becomes '$Q1R1', '$Q1R2', and so on. The function then returns the result of the evaluated statement, examining whether any of the rows' text entries match the others. The validation
tag is used to ensure the respondent answers appropriately.
With inclusion and inline lists
In the next example, listUnique
references 'T2.rows', which is a derived list. Specifically here, the client only cares about checking the first three text entries. Therefore, we have specified that the evaluation only look through the first three rows by adding '[1..3]' after 'T2.rows'. The respondent cannot repeat any text within the first three rows but can repeat text in the last two rows, or a combination of the first three and last two. Also, notice that message
can be used inline as a decorator, as in the first example, or placed on a separate line as a tag (as shown here).
With external lists
Table 3 here is similar to table 1 above, but instead uses an external list established with the set list
widget.
Autoother options
In addition to referencing table rows, you can also reference autoother text input to ensure the text written in the field is unique. The list is a collection of the previous BRANDS list at Q3, plus three new autoothers. If the respondent chooses to fill in two or three fields, the text must be unique. If the respondent does not use them, or only fills in one, they can proceed as normal. Given that we only want to validate unique responses for the autoothers, we have specified only to evaluate the option IDs '[971..973]'. Also, it is worth noting that autoothers' field references are constructed as 'QX_[id]_OTH', where X is the question number, '[id]' is the option ID, followed by '_OTH'.
Closed-ended tables
Although less common, you can also force every row in a closed-ended table to have a unique response. In the table below, every brand is forced to select a different option.
Comments
0 comments
Please sign in to leave a comment.