Logic, rules, and conditions
Logic uses rules to set conditions for an action to tailor the different assets and entities within Medallia Experience Cloud, such as Experience programs, Surveys, Alerts, etc., based on your different company needs. For example, if your company has several brands, you may need to send out a different survey to customers of each brand, using a conditionally customized design. In surveys, you may want to show a question only to survey takers who are above 18 years old, and another to those who answered Yes to a specific question, or you might want to trigger an alert email only when respondents leave certain scores.
Rules and conditions appear in:
Display logic
Display logic, previously known as Precondition, defines the conditions under which a survey is sent out, a survey page, group, or content element, field, choice set, or Case form questions is shown, or an Alert is applied. It must be met before sending the survey, showing the survey page, group or content in the survey, or creating a case management form, or alert.
Click Add rule to reveal the Rule builder. Click the display logic menu or hover over the icons to edit or delete the rule.
Rule builder
Rule builder builds the display logic rules in Surveys, Survey designs, Distributions, Rules, Dynamic Case Forms, and Alert rules. Each line in a rule is a condition composed of a field, an operator, and potentially a value if required by the operator. Fields store data such as names, countries, regions, etc., as well as questions that can be used for conditioning. For example, this image shows a simple rule with one condition that will show a page only for survey takers with a Region value of North:
Multiple conditions in the same rule group are controlled by the group's header line, which determines how conditions in that rule group are matched. For example, this rule establishes that a survey page is shown to survey takers with a Region value of North, except those in the State of Oregon.
Rule group uses these operators:
| Operator | The rule group matches conditions when... |
|---|---|
| All | All of the conditions match. |
| Any | Any of the conditions match. |
| At least | At least the number of conditions you enter match. |
| At most | At most the number of conditions you enter match. |
| More than | More than the number of conditions you enter match. |
| Less than | Less than the number of conditions you enter match. |
| Exactly | The exact number of conditions you enter match. |
To add and remove conditions, use the icons shown in this image:
Nested conditions
You can create more complex, nested groups of conditions in the Rule builder. For example, this rule includes two groups of conditions. The first group's header indicates that everything within it must resolve as true. Because that group includes a nested group, that nested group must also resolve as true. The header for that nested group indicates that for it to resolve as true, everything within it must resolve as true.
To move conditions to different levels of nesting, use the icons shown in this image:
Rule expression
As you work in the Rule builder, the Rule expression line updates to show the full syntax that defines the rule. You can edit directly in the expression, or type a full rule expression manually if you are familiar with the syntax. Click copy to copy and paste an expression from one rule to another.
Note that if you make any changes directly in the expression line, you can click check to verify if its syntax is correct.
Click Done to save the rule. After saving it, you can see the expression directly in the property it's being applied to:
Operators
You can select from these operators when adding conditions in the Rule builder:
| Operator | The survey is distributed when: | The survey page, content or group is displayed when: | The design, email or distribution setting rule is chosen when: | The Case form questions are shown when: | The Alert applies when: | The Experience program uses a shared asset when: |
|---|---|---|---|---|---|---|
| is present | The field is present in the survey. With this operator, you cannot set a value. | The field is present in the page, group, or content element. With this operator, you cannot set a value. | The field is present in the design, email or distribution setting rule. With this operator, you cannot set a value. | The field is present in the case form. With this operator, you cannot set a value. | - | - |
| is missing | The field is not present in the survey. With this operator, you cannot set a value. | The field is not present in the page or content element. With this operator, you cannot set a value. | The field is not present in the design, email or distribution setting rule. With this operator, you cannot set a value. | The field is not present in the case form. With this operator, you cannot set a value. | - | - |
| equal to | The field matches the value you enter. | - | The field matches the value you enter. | |||
| does not equal to | The field has any value except the value you enter. | - | - | |||
| in the list | The field has a value matching any of the values you choose. | |||||
| not in the list | The field has a value not in the list of values you choose. | - | ||||
| contains | The field has the value you enter. | - | - | |||
| does not contain | The field does not have the value you enter. | - | - | |||
| greater than | The field is greater than the value you choose. | - | - | |||
| lower /less than | The field is lower than the value you choose. | - | - | |||
| greater or equal than | The field is greater than or equal to the value you choose. | - | ||||
| lower/ less or equal than | The field is lower than or equal to the value you choose. | - | ||||
Note that operators available to choose vary depending on the field data type. For more information, see Supported field data types below.
Operators for Multi-valued fields
When using Multi-valued fields — fields that store multiple values — select from these operators:
| Operator | The survey is distributed when: | The survey page, content or group is displayed when: | The design, email or distribution setting rule is chosen when: | The alert applies when: |
|---|---|---|---|---|
| is present/ is in the list | The field is present in the survey. With this operator, you cannot set a value. | The field is present in the page or content element. With this operator, you cannot set a value. | The field is present in the design, email or distribution setting rule. With this operator, you cannot set a value. | The field has a value matching any of the values you choose. |
| is missing/ has no value | The field is not present in the survey. With this operator, you cannot set a value. | The field is not present in the page or content element. With this operator, you cannot set a value. | The field is not present in the design, email or distribution setting rule. With this operator, you cannot set a value. | The field has no value. |
| selected all | The field has all the values you choose. | |||
| selected any | The field has any of the values you choose. | |||
| selected only | The field matches the exact values you choose. | |||
| selected at least | The field has at least the number of values you choose. | |||
| selected at most | The field has at most the number of values you choose. | |||
| selected less than | The field has less than the number of values you choose. | |||
| selected more than | The field has more than the number of values you choose. | |||
| selected exactly | The field has the exact number of values you choose. | |||
For more information, see Multi-valued fields and Conditional expressions.
Fields
These field categories are available to use:
| Field categories | Available in: |
|---|---|
| Event fields | Experience programs, surveys, survey pages, groups, content elements, designs, emails, distribution settings, case forms, and alerts. |
| Contact fields | |
| Feedback fields | |
| Unit data fields (u_fields) | Surveys, survey pages, groups, content elements, design, emails, distribution settings, and case forms. |
| Unit group data fields (ug_fields) | |
| System fields | Surveys, designs, emails, distribution settings, and case forms. |
| K-fields | |
| Metadata fields (M-fields) | Surveys, pages, groups, and content elements. Restriction: Only these Metadata fields are supported:
|
Supported field data types
| Data type | Supported operators |
|---|---|
scale | is present, is missing, equal to, does not equal to, in the list, not in the list, greater than, lower than, greater or equal than, lower or equal than |
choice set | is present, is missing, equal to, does not equal to, in the list, not in the list. |
unit | is present, is missing, equal to, does not equal to, in the list, not in the list, contains, does not contain |
autoindex_text | is present, is missing, equal to, does not equal to, in the list, not in the list, contains, does not contain. |
mvalt | See Operators for Multi-valued fields above. |
text | is present, is missing, equal to, does not equal to, in the list, not in the list, contains, does not contain. |
comment | |
translatable comment | |
email | |
country | |
phone |
JavaScript validation
-
Set a field value — Parse data from questions that the survey taker answered in previous pages, groups or content element to set values elsewhere in the survey.
-
Validate input — Enforce data constraints in fields, such as special characters, date validation, the number of characters, and so on.
-
Modify page elements — Alter survey styling or wording based on data entered by the survey taker.
Set a field value
// "q_retailstore_receipt_code" is the Question ID that corresponds to the question in the survey that asks for the survey taker's receipt code.
var receiptCode=fields.get("q_retailstore_receipt_code");
var storeId=receiptCode.substring(0,3);
fields.set("q_retailstore_unit",storeId);Validate input
These JavaScript validation snippets are examples that can be used to validate inputs in the different survey content elements, applied on individual questions. When a survey taker tries to move on to the next page of the survey, this is validated. If the content does not meet the requirements, an error message is displayed at the top of the survey page and next to the corresponding question.
//Set a variable to the information stored in a field.
var CodeVar = fields.get("field_id");
//Set a valid pattern for a string of text.
var codeRegex = <string pattern>;
//Test the information stored in the variable against the string pattern.
codeRegex.test(codeVar);
//Set a variable to the information stored in a field.
var CodeVar = fields.get("field_id");
//If not NULL, set the field (e_unitid) to the variable.
if(codeVar === null) return false;
//If not NULL, set the field (e_unitid) to the variable.
fields.set("e_unitid",codeVar);
Consider the common scenarios for input validation:
-
Receipt code validation — Validation on a code field to ensure that the survey taker has entered their receipt code in the correct format (123-4567-89). In this case, you can validate a text string against this pattern using the Regular Expression (RegEx) JavaScript function to compare the text string against that pattern as follows:
// "q_retailstore_receipt_code" is the Question ID that corresponds to the question in the survey that asks for the survey taker's receipt code. var code = fields.get("q_retailstore_receipt_code"); codeRegex = /^\d{3}-\d{4}-\d{2}$/; codeRegex.test(code); -
Phone number validation — Validate the text entered into the phone number field to ensure it matches the correct phone number patterns (123-456-7890, (123)-456-7890, (123)456-7890, (123)4567890, 1234567890, 123.456.7890):
// "q_phone_number" is the Question ID that corresponds to the question in the survey that asks for the survey taker's email address. (function () { var phone = fields.get("q_phone_number"); if (!phone) { // To allow empty or null phone numbers through, un-comment this line // return true; // To allow empty or null phone numbers through (e.g., required question), un-comment this line // return false; } var phoneRegex = /^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/; return phoneRegex.test(phone); }()) -
Email validation — Validate the email address entered into the email address field to ensure it matches the correct email addresses patterns (surveytaker@example, survey.taker@example.com, survey.taker@example.co.uk, surveytaker+123@example.com, survey_taker@example.com):
// "q_email_address" is the Question ID that corresponds to the question in the survey that asks for the survey taker's email address. (function () { var email = fields.get("q_email_address"); if (!email) { // To allow empty or null email address through, un-comment this line: // return true; // To allow empty or null email address through ( such as in a required question), un-comment this line: // return false; } var emailRegex = /[^\s@]+@\S+/; return emailRegex.test(email); }())
For more information, see Conditional expressions and JavaScript in Experience Cloud.
