The Assette Data Object Editor supports a variety of expressions and functions that allow you to manipulate and evaluate data effectively. One of the fundamental logical operators available is the “AND” expression, which is used to combine multiple conditions in a single logical statement.
Logical Operators Overview #
Before diving into the “AND” expression, it’s important to understand the basic logical operators supported by the Data Object Editor that has been used throughout this article:
- Equals (
==
): Checks if two values are equal.- Example:
"String" == "String"
returns<em>true</em>
.
- Example:
- Not Equal To (
<>
): Checks if two values are not equal.- Example:
100 <> 12
returns<em>true</em>
.
- Example:
- Less Than (
<
): Checks if the left value is less than the right value.- Example:
9 < 8
returns<em>false</em>
.
- Example:
- Less Than or Equal To (
<=
): Checks if the left value is less than or equal to the right value.- Example:
8 <= 9
returns<em>true</em>
.
- Example:
- Greater Than (
>
): Checks if the left value is greater than the right value.- Example:
9 > 8
returns<em>true</em>
.
- Example:
- Greater Than or Equal To (
>=
): Checks if the left value is greater than or equal to the right value.- Example:
8.5 >= 8
returns<em>true</em>
.
- Example:
- Not (
not
): Negates a condition.- Example:
not(price > 100)
returnstrue
ifprice
is less than or equal to100
.
- Example:
The “AND” Function #
- The “AND” function allows you to combine multiple logical conditions. It returns
true
only if all the conditions aretrue
; otherwise, it returnsfalse
.
Syntax #
(condition1) and (condition2) and (condition3) ...
Each condition should be enclosed in parentheses for clarity and proper evaluation.
How it Works #
- Evaluation Order: The conditions are evaluated from left to right.
- Short-Circuit Evaluation: If any condition evaluates to
false
, the entire expression returnsfalse
immediately without evaluating the remaining conditions.
Examples #
Numeric Comparison
Check if a price
is greater than 100
and less than or equal to 1000
:
(price > 100) and (price <= 1000)
String Comparison
Verify that a productName
starts with "Pro"
and ends with "X"
StartsWith(productName, "Pro") and EndsWith(productName, "X")
Date Comparison
Determine if a date
falls within a specific range.
(date >= Date(2023, 1, 1)) and (date <= Date(2023, 12, 31))
Combining Multiple Conditions
Check if an item is in stock, costs less than $50
, and belongs to the "Electronics"
category
(isInStock == true) and (price < 50) and (category == "Electronics")
Using “AND” with Other Functions #
You can combine the “AND” expression with other functions to perform more complex evaluations.
Using “AND” with HasValue
#
Ensure that a variable has a value before performing a comparison. This checks if discount
is not null
or undefined
and greater than 0
.
HasValue(discount) and (discount > 0)
Using “AND” with String Functions #
Check if a username is not empty and meets certain criteria. This expression returns true if username is not empty and contains an “@” character.
not IsEmpty(username) and Contains(username, "@")
Grouping Conditions #
Use parentheses to group conditions and control the order of evaluation. The “AND” expressions are grouped to define the two ranges. The “OR” operator combines the two ranges.
((number >= 1) and (number <= 10)) or ((number >= 20) and (number <= 30))
Practical Tips #
Enclose Conditions
Always use parentheses around each condition to ensure they are evaluated correctly.
Case Sensitivity
By default, string comparisons are case-sensitive. Use the ignoreCase: true
parameter if needed.
StartsWith(name, "john", ignoreCase: true) and EndsWith(name, "doe", ignoreCase: true)
Null Checks
Use HasValue
to prevent errors when variables might be null
or undefined
.
HasValue(score) and (score >= 50)
Filtering Data
Filter a dataset to show only items that match all criteria
(category == "Books") and (price < 20) and (rating >= 4)