Table of Contents:
What is an Expression Mapping?
The "Expression" data binding option allows to map each Answer Option to more complex rules. These rules allow mapping an Answer Option to expressions containing values of different product attributes. Thus, expression mapping is the most powerful of the three Types of Answer Option Data Binding.
Since the binding of Answer Options to data attributes can differ for each Answer Option, the configuration dialog for the attribute binding is placed in the Answer Option properties dialog and not in the Question (compare to Single Attribute Connection in Answer Option).
When is the Expression Mapping Recommended?
- Whenever you need a more complex logic with AND (conjunction) or OR (disjunction) statements.
- e.g. examples in How to Configure More Than One Logical Operator?
- Whenever you want to connect one Answer Options to several data attributes.
- If you want to use mathematical comparison operators, like less or greater, in connection with attributes of type number.
- e.g. for the price attribute
- Attribute: You can choose any product attribute from the uploaded product data file. This also gives you the flexibility to build expressions for one Answer Option across a variety of product attributes.
- Cond. ("condition"): Set the mathematical operator that compares the Attribute with the selected Value.
- For data attributes of the type "Text" or "Boolean" you can choose between the "=" (equal) and "≠" (unequal) operators.
- For attributes with type "Number" you may also select the operator "<" (less), "<=" (less equal), ">" (greater) or ">=" (greater equal).
- All possible mathematical operators are: =, ≠, <, <=, >, >=
- Value: Represents one data attribute value from the selected product attribute.
- Logical operator: You can select "AND" (conjunction) and "OR" (disjunction) operators between two expression rows.
- "AND" means that both expressions have to be true at the same time for a product to match. The example in Connect a Single Attribute to an Answer Option will be interpreted as: a product should cost between 500 and 1000.
- "OR" means that at least one of the two expressions has to be true to match with a product.
Example and its Configuration steps
It is assumed that you want to ask a Question about the price range a user is willing to spend. Every Answer Option represents a certain price range.
These price ranges can easily be expressed with mathematical operators. Therefore change the "Answer Option Data Binding" to the type "Expression" in the "Data Binding and Connections" tab (see image below).
Product Data File
Furthermore your uploaded product data file contains the product attributes "price", "hdmi_port" and "display_resolution" which are used in this example.
- id: unique product identifier
- name: product name
- price: product price
- hdmi_port: Boolean value which signals whether the product contains HDMI connectors.
- display_resolution: Describes how good is the resolution of the TV screen.
Connect a Single Attribute to an Answer Option
Afterwards you can enter expressions for each Answer Option of this Question. The goal is to build a price range from 500 to 1000 € which represents the medium budget range.
The following steps describe how to configure this range:
- Click on the Answer Option label, e.g. on "medium budget". The Answer Option properties dialog shows up.
- Go to the "Data Binding and Connections" tab.
- Select the attribute "price" in the combobox "Attribute".
- Choose the mathematical operator ">=" (greater than or equals) in the combobox "Cond.".
("Cond." stands for "condition")
- Afterwards select or type the value "500" in the combobox "Value".
- Furthermore add another expression. Click on the button "Add Expression". This creates another expression row. Additionally, a logical operator between the two expression rows is added.
- Make sure that the logical operator combobox is set to "AND".
- In the new expression row select the attribute "price" again.
- Choose the mathematical operator "<=" (less than or equals).
- Select the value "1000".
After these steps, the desired price range is set for the Answer Option "medium budget".
Each expression row can be deleted by clicking on the "X" button on the right side of each row.
Connect Multiple Attributes to an Answer Option
The following example shows a more complex case of binding your Answer Options to multiple product data attributes.
It is assumed that you want to ask the user for what he wants to use his TV. Most of the times, different use cases require dependencies to several data attributes.
Assume a case where the user wants to buy a TV for gaming:
In this example, you connect the Answer Option "use the TV for video games..." with the two attributes "hdmi_port" and "display_resolution" (see Attribute Description). You want to achieve that the TV has at least one HDMI port for the console and Full-HD resolution for a good gaming experience. That is why you select the values "yes" for "hdmi_port" and "full_hd" for "display_resolution". Moreover make sure that the logical operator is set to "AND".
How to Configure More Than One Logical Operator?
There are three different kinds of configurations:
- Only conjunctions:
e.g. "Price <= 999 AND Price >= 499 AND ..."
- Only disjunctions:
e.g. "Gender = female OR Gender = unisex OR ..."
- Mix of "AND" and "OR" in one expression:
e.g. "Price <= 999 AND Price >= 499 OR Gender = female"
All conjunctions bind stronger than disjunctions. That means that brackets are set implicit. In the last example above, the bracket would be set as follows: "( Price <= 999 AND Price >= 499 ) OR Gender = female"