Runtime & expressions

Question proxies

Every accessor available on a question proxy, organised by question type. The exhaustive reference for what `Q.something` resolves to.

What a proxy is

When a script or expression references Q1, the runtime returns a proxy — an object that exposes accessors and methods to inspect or modify the question’s state. The proxy is named after the qid.

Common accessors (most types)

These accessors work on most answer-bearing types:

AccessorReturnsMeaning
Q.answeredboolThe respondent has provided an answer.
Q.notAnsweredboolMirror of Q.answered. Useful for guard clauses that read more naturally as a positive condition.
Q.valuescalarScalar answer. single returns the option code (numeric-string); number returns the number; open returns the text. None if not answered.
Q.allcollectionAll codes the question can show — the visible domain. Available on single, multi, rank, openList, numberList, gridSingle, gridMulti (plus their rows), cardSort, and loop iterators. Not on open, number, lookup, gridNumber, cbc, maxdiff, or annotation types.
Q.allLabelscollectionLabels parallel to Q.all. Same scope as Q.all.

.label is not a generic top-level accessor — it lives on row, entry, column, lookup, and task/item receivers (where the proxy itself represents a single labelled thing). For the answered label on a single, use Q.selectedLabel.

single

QBrand.value           # "2" — the chosen code (numeric-string)
QBrand.selected        # collection containing the one code
QBrand.selectedLabel   # "Samsung" — the label of the chosen option
QBrand.answered        # True / False

.matched is a lookup-only accessor — see the lookup section below.

Reading a question that lives inside a loop

When a question is declared inside a - loop: body, every loop iteration produces its own answer slot. Inside the loop body, QRating.value reads the current iteration’s answer automatically. Outside the loop — or to read a different iteration from inside — reach it through the trailing- underscore form of the qid:

QRating_1.value            # static — Apple's rating (code 1)
QRating_[code].value       # dynamic — whatever code the local holds

For nested loops the codes concatenate outer-to-inner: QRating_1_10 or QRating_[1][10].

Full surface and worked examples: Loops → Reading a specific iteration’s answer.

multi

QFeatures.value           # not meaningful on multi — use .selected
QFeatures.selected        # collection of selected codes
QFeatures.selectedLabels  # collection of selected labels
QFeatures.answered        # True / False
QFeatures.row(2).label    # the label of code 2 (entry proxy — .label only)

# Mutation
QFeatures.set([1, 3, 5])  # replace the selection
QFeatures.add(7)          # add code 7 to the selection
QFeatures.remove(7)       # remove code 7 from the selection
QFeatures.reset()         # wipe the selection

Q.row(N) on a multi returns an entry proxy with only .label available — it’s a lookup of the option label by code, not a full row object the way grid rows are.

rank

QTop3.selected         # set of ranked codes (preserves order)
QTop3.selectedLabels   # labels in chosen rank order
QTop3.values           # ordered code list (parallel to .selected, typed as a list)
QTop3.answered

.selected and .values both reflect the rank order; the distinction is shape — .selected is a code set with collection methods (.any, .intersect, etc.), .values is a typed CodeList you can index with .at(N).

open

QFeedback.value        # the text
QFeedback.answered

openList

QExamples.row(1).value   # text in row 1
QExamples.row(2).value   # text in row 2
QExamples.values         # collection of all row values (in row order)
QExamples.answered       # True if any row has text
QExamples.row(1).answered  # row-level answered

number

QAge.value             # the number
QAge.answered

numberList

QSpend.row(1).value    # number in row 1
QSpend.values          # collection of all row values
QSpend.answered        # True if any row has a value
QSpend.row(1).answered # row-level answered

To sum a numberList, iterate .all and accumulate row values: see Patterns.

gridSingle

QSatisf.row(2).selected         # collection — the row's selection
QSatisf.row(2).selectedLabel    # the label
QSatisf.row(2).value            # alias for the selected code
QSatisf.row(2).answered
QSatisf.values                  # codes per row, in row order
QSatisf.all                     # all codes the rows can hold (the scale)

gridMulti

QFeatures.row(2).selected            # collection of codes selected in row 2
QFeatures.row(2).selectedLabels      # labels for those codes
QFeatures.row(2).answered
QFeatures.row(2).selected.any(3)     # True if code 3 is selected in row 2

# Mutation — gridMulti rows take .add / .remove / .set just like a multi
QFeatures.row(2).add(3)
QFeatures.row(2).remove(3)
QFeatures.row(2).set([1, 3])

Note .any(...) is a method on the collection (.selected), not on the row proxy itself — write row(2).selected.any(3), not row(2).any(3).

gridNumber

QBudget.row(1).col(2).value      # the number in row 1, col 2
QBudget.col(2).row(1).value      # same cell, different drill direction
QBudget.row(1).values            # collection of values across the row
QBudget.col(2).values            # collection of values down the column
QBudget.row(1).answered

gridNumber does not expose Q.all for question-level iteration — list authored row codes explicitly when you need to walk every row. To sum a row or column, pass .values to sum(...) (see Patterns).

lookup

Single-record lookup

QZip.value          # the matched primary value
QZip.label          # display label of the matched record
QZip.matched        # True if a record matched, False otherwise
QZip.answered       # True if all steps resolved
QZip.field("city")  # value of a named field on the matched record
QZip.record         # the full matched record (object)

For cascading lookups, each step is addressable as a direct property of the parent question — name the step ID after the qid, no .step(...) indirection:

QVehicle.make.value     # the chosen make's value
QVehicle.make.label     # the chosen make's display label
QVehicle.model.value    # next step in the cascade
QVehicle.year.value

See lookup.

Multi-record lookup (multi: True)

When the lookup is configured for multi-select, additional accessors expose every matched record:

QPlaces.records             # list of matched record objects
QPlaces.values              # list of selected primary values (selection order)
QPlaces.labels              # list of labels in selection order
QPlaces.size                # how many records selected

# Mutation
QPlaces.add("BOS")          # append a value to the selection
QPlaces.remove("BOS")       # remove a value from the selection
QPlaces.reset()             # wipe the selection

cbc / maxdiff

CBC and MaxDiff have task-aware accessors. Each task is addressed via Q.task(N), which returns a task slice — and both types expose question-level accessors that read the current task during in-task follow-ups (and the most-recently-completed task afterwards).

CBC

Concept N is the 1-based column index: concept 1 → letter A, concept 2 → B, … Addressed numerically throughout — there is no letter / bracket form (ratings["A"] and ratings.A both do not exist).

# Question-level — read the current task
QCbc.selected             # CodeSet — concept code chosen (0 = None, A = 1, B = 2, …)
QCbc.ratings(N)           # rating code concept N got (rating mode)
QCbc.rank(N)              # rank POSITION concept N got, 1-based (rank mode)
QCbc.answered             # bool

# Per-task — same shape, reach any task by number
QCbc.task(1).selected     # CodeSet — chosen concept in task 1 (choice mode)
QCbc.task(1).ratings(N)   # rating code concept N got in task 1 (rating mode)
QCbc.task(1).rank(N)      # rank POSITION concept N got in task 1 (rank mode)

QCbc.selected, QCbc.ratings(N), QCbc.rank(N) (and the task(T).… forms) all support numeric comparison, .any([…]), and piping ({{ }}).

MaxDiff

# Question-level — best / worst of the current (or
# most-recently-completed) task
QMxd.best                 # MxdItem
QMxd.worst                # MxdItem
QMxd.best.code            # the item code
QMxd.best.label           # the item label
QMxd.best.answered        # bool
QMxd.best.any([5, 6])     # membership test on the item code

# Per-task — reach any task by number
QMxd.task(1).best         # MxdItem
QMxd.task(1).worst        # MxdItem

.best and .worst are properties, not callable with an index — use .task(N).best for per-task access. The question-level .best / .worst return single MxdItem proxies for the most-recently-completed task, useful for piping ({{ QMxd.best }} resolves to the item’s label) and guard conditions (if QMxd.best.any([5, 6]):).

MxdItem proxies are not collections — there’s no .size, .intersect, .labels, etc.

See CBC and MaxDiff.

cardSort

cardSort exposes every option-and-slot pair through two collections:

QSort.all                  # OptionCollection — every option being sorted
QSort.allSlots             # SlotCollection — every slot the options can land in

QSort.option(3).slot       # which slot code option 3 was placed in (or None)
QSort.option(3).slotLabel  # the slot's label
QSort.option(3).placed     # True if the option was placed in any slot
QSort.option(3).code       # the option's code
QSort.option(3).specify    # the typed specify text, if any

QSort.slot(1).options      # options placed in slot 1
QSort.slot(1).label        # slot 1's label
QSort.slot(1).code         # slot 1's code
QSort.slot(1).isCustom     # True if it's a respondent-added slot

The two top-level collections support .all(fn) / .any(fn) / .size for predicate-based queries. Pass a def-defined predicate (the Python subset doesn’t accept lambda):

- script: |
    def is_placed(o):
        return o.placed

    def is_custom_slot(s):
        return s.isCustom

    if QSort.all.all(is_placed):
        hAllPlaced.set(1)

    if QSort.allSlots.any(is_custom_slot):
        hHasCustomSlot.set(1)

See cardSort.

Setters — writing answers programmatically

Hidden helper questions or any author-mutable target accept the same four mutators across the type surface:

hRegion.set(1)             # single — set the chosen code
hChannels.set([1, 2, 3])   # multi — replace the selection
hChannels.add(4)           # multi — add a code
hChannels.remove(2)        # multi — remove a code
hChannels.reset()          # any type — wipe back to unanswered
hQ.row(1).set(3)           # grid row — same shape as the parent type

See the per-question-type pages for the validation rules each setter enforces (e.g. single rejects out-of-domain codes, rank rejects duplicates).

.set(...) and .reset() are write-terminal — they return None, so call them on their own line. Don’t capture the result or chain off them; the validator flags question-write-assign if you do. .add(...) and .remove(...) on the other hand are fluent (return the collection) and are safe to chain. See Scripts → Fluent vs. write-terminal for the full distinction.

Specify-text setters

Options with specify: True get a sub-accessor for the typed text:

QBrand.specify(99).value      # the typed-in text on code 99
QBrand.specify(99).answered   # True if the respondent typed something
QBrand.specify(99).set("...") # write the specify text
QBrand.specify(99).reset()    # clear it

See Properties → Choices & domains for the specify: declaration.

See also

  • Collections — methods on the value .selected returns.
  • Row & cell access — .row() / .col() semantics.
  • Loops — loop_id.* accessors and the Q_[code] trailing-underscore form for reading a specific iteration’s answer.
  • Question types — per-type details.