Conditional expressions
A conditional expression is a construct that evaluates to either yes (true) or no (false). Many fields in Medallia Experience Cloud support these expressions. The most common use of a conditional expressions are survey conditions that determine which survey records meet a specified criteria. Some features that use conditional expressions are:
For example, in Setup Exports you can create a survey condition to filter the set of records returned from the database before exporting them.
You can construct conditional expressions from these components:
Also see:
Logical constants
In the simplest form, an expression is just one of these constant values:
| Constant | Description |
| TRUE | Always true; match all |
| FALSE | Always false; no matches |
Using these in a would mean that all records either meet or do not meet the criteria.
TRUE constant: all records match.Comparative operators
| Operator | Description |
|---|---|
| = | Equal to |
| != | Not equal to |
| < | Less than |
| <= | Less than or equal to |
| > | Greater than |
| >= | Greater than or equal to |
| ~ (tilde) | Contains the string value (case-insensitive) |
| !~ | Not contains the string value |
For example, to identify records associated with a brand named Orion, use a simple equals (=) operator: ug_survey_brand = 'Orion'.
The tilde (~) matches when the field contains string value, regardless of the case of the letters. For example, this expression matches alert owners named "Nancy Roberts" and "Bert Marks": a_alert_owner ~'bert'.
<, <=, >, and >= comparative operators are supported for integer and monetary fields only. To condition on fields with discrete Alternative set values, use the = and != comparative operators, and the IN{}, MISSING, and present special operators described below.Logical operators
Logical operators combine multiple criteria.
| Logical operator | Description |
|---|---|
| AND | All conditions match |
| NOT | Next condition doesn't match |
| OR | Either condition matches |
For example, OR means that either brand name Orion or Rigel match: ug_survey_brand = 'Orion' OR ug_survey_brand = 'Rigel'.
Parenthesis combine complex expression criteria and can provide logical grouping and clarity: (ug_survey_brand = 'Orion') OR (ug_survey_brand = 'Rigel').
The NOT operator returns the opposite of the condition that follows it. In this example, the condition matches all Orion brand units that are not in the California region: (ug_survey_brand = 'Orion') AND NOT (ug_region = 'California').
Similarly, the exclamation mark can negate an operator, like this: (ug_survey_brand = 'Orion') AND (ug_region != 'California').
Special operators
Special operators are shortcuts for common situations that would involve complex expressions with the basic operators.
| Special operator | Meaning |
|---|---|
| IN { x1, … , xn } | The field has one of the values listed in the braces. Use braces {}, not parenthesis (). |
| MISSING | The field's value is null. |
| present | The field has a value. |
| SCRIPT('JavaScript') |
Runs the JavaScript snippet, which returns a Boolean true or false. For more information, see JavaScript functions. Note:
SCRIPT() runs the snippet against every record to be compared, which can impact performance. Consider creating a Formula field (K-Field) to perform the calculation instead. That field returns a value that can be used in a simple equals test, like FormulaField = 1. |
For example, the first example above tests the ug_survey_brand field for multiple possible values using the OR operator and, if either of them are true, then the entire expression is true. The same expression can be restated with the IN-set operator, like this: ug_survey_brand IN { 'Orion', 'Rigel' }.
The present and MISSING special operators can test for the presence or absence of a value in a field. This example is true when the Feedback field (Q-field) has a value. This field might not have a value if the survey taker did not answer the question: q_support_satisfaction present.
In JavaScript, the present and MISSING operators do not work with comment and text fields. To test those field type, compare the field to a empty string instead. For example, to see if a comment field contains text use q_comment != ''
Use parenthesis to add clarity to complex expressions such as: ( ug_survey_brand IN { 'Orion', 'Rigel' } ) AND ( q_support_satisfaction present )
The SCRIPT operator contains a JavaScript function or expression that returns a Boolean true or false. This example from a survey node condition returns false until the survey is complete: SCRIPT("if (fields.get('m__finish_date')==null) { false } else { true }")
Count operators
Count operators evaluate multiple conditional expressions, and then return a match depending on how many of the expressions are true.
| Count operator | Meaning |
|---|---|
| At most x of { exp1, … , expn } | Up to x count of the expressions is true. |
| At least x of { exp1, … , expn } | At least x count of the expressions is true. |
| Less than x of { exp1, … , expn } | Less than x count of the expressions is true. |
| More than x of { exp1, … , expn } | More than x count of the expressions is true. |
| Exactly x of { exp1, … , expn } | Exactly x count of the expressions is true. |
This example is true when the survey taker answered at least one satisfaction question out of a list of two restaurants and a bar: at least 1 of { q_osat_restaurant_1 present, q_osat_restaurant_2 present, q_osat_bar present }
This example is true when the survey taker answered either two or all three satisfaction questions out of a list of two restaurants and a bar: more than 1 of { q_osat_restaurant_1 present, q_osat_restaurant_2 present, q_osat_bar present }
This example is true when the survey taker left at least one satisfaction question unanswered (or all of them) out of a list of three: at most 2 of { q_overall_satisfaction present, q_food_quality present, q_service_level present }
Using Multi-valued fields in conditions
Multi-valued fields support storing multiple values in a Feedback or Event field. There are two functions you can use in conditions:
mvGet(String mvFieldKey)— Fetches a value from a Feedback field.mvSet (String mvFieldKey)— Sets specific JavaScript validation values to a multi-valued Event field.
mvGet function in the content element's JavaScript validation, which has the format of mvGet(String mvFieldKey);. For example:"SCRIPT("fields.containsAll(fields.mvGet('q_packages_bp_branch_channels_used_mvalt'), [1]) && fields.mvGet('q_packages_bp_branch_channels_used_mvalt').length > 1")"
The following line returns true if the q_packages_bp_branch_channels_used_mvalt field has a choice set item of Yes (or an alternative option with a SequenceNumber of 1): fields.containsAll(fields.mvGet('q_packages_bp_branch_channels_used_mvalt'), [1])
The following line from the example returns true if the number of values in the field is greater than 1: fields.mvGet('q_packages_bp_branch_channels_used_mvalt').length > 1
Tips
- Avoid using a conditional expression when you can use a filter instead, such as in export specifications. Filters are database queries that run faster than conditional expressions, and the condition is applied to the data set returned by the filter; the condition runs against each record returned by the filter.
- Consider using K-fields to perform complex conditional calculations, then reference the field in the conditional expression like
kField = 1, which runs considerably faster than the complex expression.
