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.

Note: In Surveys, access Display logic from the Distribution tab under Personalized invitations. In Emails, Rules and Design rules you can access it from the Rules tab or Rule property.

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:

Rule builder is made up of conditions, which include a field, an operator and potentially a value if required by the operator.

Tip: For survey pages, groups, and content elements you can also use JavaScript expressions.
Turning on the NOT property for a condition does the opposite of what you enter in that line. For example, this image shows a rule with one condition that displays a page for survey takers on every Region except the North:

Select NOT to make the condition do the opposite of what is entered in that line.

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.

u

Rule group uses these operators:

OperatorThe rule group matches conditions when...
AllAll of the conditions match.
AnyAny of the conditions match.
At least At least the number of conditions you enter match.
At mostAt most the number of conditions you enter match.
More thanMore than the number of conditions you enter match.
Less thanLess than the number of conditions you enter match.
ExactlyThe exact number of conditions you enter match.

To add and remove conditions, use the icons shown in this image:

Rule conditions actions allow for adding a a condition line below the current condition, nest the current condition under a new group or delete the current condition.

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.

Conditions can be nested under groups within the same rule.

To move conditions to different levels of nesting, use the icons shown in this image:

Nested conditions actions allow for adding a new condition below the current condition of the nested group, create a new nested group or condition, un-nest the current group or condition and delete the current condition within the nested group.

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 icon. copy to copy and paste an expression from one rule to another.

Rule expression updates in real-time while building the rule conditions.

Note that if you make any changes directly in the expression line, you can clickCheckmark icon. check to verify if its syntax is correct.

Click the 'Check' icon to make sure the rule definition 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:

Expression shows: e_bp_digital_region_auto = "North" and not e_state = "Oregon" and (q_bp_b2b_product_osat_scale in {1, 2, 3} or q_bp_branch_associate_osat_scale in {4, 5, 6})

Operators

You can select from these operators when adding conditions in the Rule builder:

OperatorThe 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 presentThe 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 missingThe 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 toThe field matches the value you enter.-The field matches the value you enter.
does not equal toThe field has any value except the value you enter.--
in the listThe field has a value matching any of the values you choose.
not in the listThe field has a value not in the list of values you choose.-
containsThe field has the value you enter.--
does not containThe field does not have the value you enter.--
greater thanThe field is greater than the value you choose.--
lower /less thanThe field is lower than the value you choose.--
greater or equal thanThe field is greater than or equal to the value you choose.-
lower/ less or equal thanThe 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.

Note: Negative values are not supported.

Operators for Multi-valued fields

When using Multi-valued fields — fields that store multiple values — select from these operators:

Important: Only Multi-valued Feedback fields are supported.
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 valueThe 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 anyThe field has any of the values you choose.
selected onlyThe field matches the exact values you choose.
selected at leastThe field has at least the number of values you choose.
selected at mostThe 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 exactlyThe field has the exact number of values you choose.
Note: Negative values are not supported.

For more information, see Multi-valued fields and Conditional expressions.

Fields

These field categories are available to use:

Field categoriesAvailable 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 fieldsSurveys, 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:
  • Set language (m__language).
  • Version ID (m__spec_id).
  • Mobile device access (m__is_mobile).
  • Screen reader active (m__screen_reader_enabled).
  • Anonymous survey name (m__feedless).
  • Anonymous survey referrer (m__feedless_referrer).
  • Anonymous survey type (m__feedless_type).
  • Preview surveys (m__is_test_survey).
  • Survey taker's IP address (m__log_ip).

Supported field data types

You can include fields with these data types in Rule builder, each supporting these operators:
Data typeSupported operators
scaleis 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 setis present, is missing, equal to, does not equal to, in the list, not in the list.
unitis present, is missing, equal to, does not equal to, in the list, not in the list, contains, does not contain
autoindex_textis present, is missing, equal to, does not equal to, in the list, not in the list, contains, does not contain.
mvaltSee Operators for Multi-valued fields above.
textis 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

JavaScript validation can be configured outside Rule builder and it is only available for Surveys. It activates when the survey taker clicks to leave a page or group, or pass a specific content element. It must be written as JavaScript, and can accomplish several goals. For example, you might add some JavaScript validation to:
  • 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

To set values that are not visible within the survey, first add the the Feedback or Event field using a Hidden field element, which should be placed before the element where the value is being set. For example, consider an Anonymous survey where the first three digits of the receipt code entered into the survey can be used to identify the store location. Use this JavaScript validation snippet to store the first three digits of the receipt code into a Feedback field that is added to the survey using Hidden field:
// "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:

Tip: You can also validate content using the existing Text entry options.
  • 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.

Important: Medallia Experience Cloud uses a JavaScript processing engine called Mozilla Rhino — also known as the Rhino Engine — to provide flexibility for scripting. Access to the Rhino Engine is restricted by a ClassShutter mechanism, which implements arbitrary logic to determine whether Rhino can access the class. When access is denied, Experience Cloud shows an error message. To access a class that is not currently allowed, contact your Experience Cloud expert. For more information, see JavaScript allow-listing.