Personalize a survey with variables

J
Jonathan
4 min read

Variables let you personalize your surveys and invitation messages by automatically including information specific to each respondent, such as their first name, a metafield from the sending, or an answer given earlier in the survey. You can also show different text based on a condition.

Metafields variables require metafields to be added at the time of sending. These metafields can come from HL7 messages for automated sendings, or be added during manual sendings. When a respondent opens a survey through a public link, metafields, patient and attributes variables are empty, as are the conditions that use them. Answers variables and conditions based on answers always work.

Where to use variables

You can insert variables in:

  • question and instruction titles and descriptions;
  • section titles and descriptions;
  • answer choices, secondary choices, matrix rows and columns, scale labels and the unit of text questions;
  • the comment field label;
  • the email invitation message (subject, content and button text) and the SMS message.

Syntax

A variable is written between double curly braces: {{ type.name }}. The variable is replaced with the matching text when the invitation is sent or when the survey is shown to the respondent.

Example:

  • Two variables are set in an invitation message: Hello {{ patient.first_name }}, here is your follow-up for the {{ metafields.clinic }} clinic.
  • The respondent receives the following message: Hello Jeanne, here is your follow-up for the Lime Santé clinic.

Available variables

VariableDisplayed value
{{ metafields.key }}The value of the metafield attached to the sending. Replace key with the metafield key. Metafields are configured by Lime for your workspace: contact our customer support team to get the list.
{{ patient.external_patient_id }}The patient’s unique identifier (when patient tracking is enabled).
{{ patient.field_identifier }}A patient record field, for example {{ patient.first_name }}. Replace field_identifier with the field’s identifier. For an address field, add _address1, _address2, _city, _province or _postal_code to the identifier.
{{ attributes.name }}A custom patient attribute, referred to by its name in the survey’s primary language. If the name contains spaces or accents, write it between brackets and single quotes: {{ attributes['Primary physician'] }}.
{{ answers.code }}The answer given to a previous question. Replace code with the question code, set in the question’s Codes tab.
Did you know? answers variables always work. patient, attributes and metafields variables depend on the sending: in test mode or through a generic link, their fallback value is shown.

Insert a variable in a question

  1. Access the list of Surveys via the main navigation.
  1. Go to the survey detail page, then click Edit.
  1. Open the question to edit.
  1. In the Question or Description field, type the variable between double curly braces, for example {{ answers.pain }}.
  1. Click Save, then publish the survey.
Question editor with variables in the question and a condition in the description

To reuse an answer, the original question must have a code and come before the question that displays it. The code is set in the question’s Codes tab:

Codes tab of a question, with the code pain

Show text based on a condition (if / else)

You can show different text depending on an answer or a metafield. A condition starts with {% if ... %}, can offer an alternative with {% else %}, and always ends with {% endif %}.

Based on a scale answer

{% if answers.pain >= 7 %}A nurse will call you today.{% else %}Your care team at the {{ metafields.clinic }} clinic will read your answer.{% endif %}

A respondent who chose 8 sees the first text:

Respondent who chose 8: the condition shows the first text

A respondent who chose 3 sees the text after else:

Respondent who chose 3: the condition shows the text after else

Based on text (metafield or answer choice)

{% if metafields.clinic == 'Laval' %}Go to the 2nd floor.{% elsif metafields.clinic == 'Saint-Laurent' %}Go to the front desk.{% else %}Go to your clinic.{% endif %}

Available operators: == (equals), != (not equal), >, <, >=, <=, plus and and or to combine conditions.

Write the text you compare between single quotes: 'Laval', not "Laval". With double quotes, the condition does not work in questions. Only compare numbers with questions that return a number (scale, number). Comparing a text answer with a number shows an error message to the respondent.

Set a fallback value

If a variable has no value for a respondent (missing metafield, unanswered question or unknown code), nothing is shown in its place. Set a fallback value for every variable you use.

Replace a value with the default filter

Add | default: 'text' after the variable name:

Text to insertWith a valueWithout a value
Hello {{ patient.first_name | default: 'there' }},Hello Ginny,Hello there,
{{ attributes['Physician'] | default: 'Your physician' }} will read your answer.Dr. Smith will read your answer.Your physician will read your answer.
You chose: {{ answers.service | default: 'no service' }}.You chose: Emergency.You chose: no service.

Change the whole sentence with a condition

When a fallback value is not enough, use a condition:

{% if metafields.clinic %}During your visit to the {{ metafields.clinic }} clinic, how would you rate the welcome you received?{% else %}During your visit, how would you rate the welcome you received?{% endif %}

As with conditions, write the fallback value between single quotes: default: 'there', not default: "there". With double quotes, nothing is shown.

Related articles

Was this page helpful?