SCENARIO 1
You might want to set a field’s value based on the contents of another field. In this example, we want to multiply the values of two fields only if another field has a certain value.
There are these columns: Owner Text, Number Column, Number 2 and Number 3.

We want to do a calculation in [[NumberColumn]] such that [[Number2]]*[[Number3]] would only work when [[OwnerText]] is “Demo User2”. We set the validation condition, validation text, and initial value as shown below.

As per the expressions laid out, the [[Number2]]*[[Number3]] calculation only works for the list item that has Demo User2 under the Owner Text column. The form is not saved for the other two list items (4*8 and 2*8), and the validation text is displayed.
Validation expressions can be applied to many other situations to ensure that forms are only saved when the field inputs meet certain conditions.
SCENARIO 2
This is a solution for automatically updating a field value in Lightning Forms based on the selection made in another field. This is useful when a user selects a specific value in one field (e.g., ChoiceColumn), and you want to update another field (e.g., Priority) automatically.
1. Click the "{}" icon next to the "Calculated" property to open the Expression Builder


2. Enter the following expression in the Function tab of the expression builder field:
if ([[ChoiceColumn]].includes("Choice 1")) {
return "High";
}
return "";

3. This expression checks if the value **'Choice 1'** is selected in the **ChoiceColumn** field, and if so, it sets the **Priority** field to 'High'. If **'Choice 1'** is not selected, the field remains empty.
Explanation of the Code
This code works as follows:
- `[[ChoiceColumn]]`: Represents the values selected in the ChoiceColumn field.
- `.includes('Choice 1')`: Checks if ‘Choice 1’ is one of the selected values.
- `return 'High';`: Sets the Priority field to ‘High’ if ‘Choice 1’ is selected.
- `return '';`: Returns an empty value if ‘Choice 1’ is not selected.
This solution assumes that the ChoiceColumn field allows for multiple selections. If the field only allows for a single selection, the expression can be simplified to check for the selected value directly.