Conditions

Last Updated: 02-Oct-19

You can configure a condition for every UI++ element, including actions within the configuration file. UI++ evaluates the condition when it reaches an element; if the condition evaluates to false, then the element, including any sub-elements, is skipped by UI++. Attaching conditions to actions and other elements enables UI++ dynamically show or perform actions or populate other data based on the runtime environment and user input.

Conditions consist of any valid VBScript expression and generally evaluate the value of variables against some other value. Because conditions are VBScript all of the functions of VBScript are available, including standard string processing and math functions. To add a condition to an element, add the Condition attribute.

Here are a few example conditions:

<Action Type="TSVar" Name="Company" Condition='"%OSDComputerName%" = "TheBoss"'>"Acme, Inc."</Action>

<Choice Option="Maybe" Value="MAYBE" Condition='Len("%FirstAnswer%") = "5"'/>

<TextInput Variable="FourthAnswer" Condition='"%SecondAnswer%" = "Dos"' Question="What is your fourth answer?" />

Notice that the XML Condition attribute’s value uses single quotes instead of double-quotes to define its value. Using single-quotes is perfectly valid for XML and is required because VBScript surrounds string literals with double-quotes. Notice also that the second example uses a VBScript function, Len, to evaluate the condition.

Within a condition, always surround a variable name with double-quotes to ensure that VBScript treats the variable’s value as a string. Without doing this, UI++ and VBScript cannot evaluate your condition successfully.