Skip to main content

Last updated: 2024-06-07


Conditions


In this topic:


Overview


Conditions are defined in the XML format, and the structure of the XML is similar to SQL queries. Conditions are used in search and sync operations.


XML Structure


Here is an an example of a condition that specifies the object property to be evaluated (Contact.Name), the operation to be used for evaluating the property (like), and the value for the condition (A%):


XML
<condition>
  <expr prop="Contact.Name" op="like">
    <v>A%</v>
  </expr>
</condition>

Note the following:


  • A condition element contains a condition definition. Conditions can be nested, i.e., one condition can contain another condition.
  • The expr element defines a minimal Boolean expression.
  • The and and or elements (not shown in the example) can be used with expressions and conditions to represent Boolean operators.

Expression


The expr element defines a minimal Boolean expression. The left side of the expression is a property, while the right side can have one or more constant values or a property. The left-side information is defined by the following expr element attributes:


AttributeDescriptionExamples
propLeft-side property name in the format object.property.sub-property.Contact.Type
Contact.PreferredPhone.AreaCode
opThe operator that you want to use for the expression. See Operators.
fnAn optional function that can be applied to the specified property to further refine the search. See Functions.

Value


Once you define the expr element and its attributes, use the v element to define the value or values for the right side of the expression.


Note: When an expression uses the isnull or not-null operator, do not include a v element.


The v element can have the following attributes:


AttributeDescriptionNotes
typeThe value type. Acceptable types are:
• prop : property name
• const : constant value
• ref : reference to current object's property value
When no type attribute is set, SmartIntegrator assumes that the type is const.
The const type must be used when the expression uses any of these operators: between, in, like, starts, ends, contain.
The ref type is for referring objects/properties.
fnSee Functions.

Operators


The following table summarizes the operators that can be used as attributes for the expr element.


OperatorDescriptionExamples
eqEqual to
gtGreater than
geGreater than or equal to
ltLess than
leLess than or equal to
neNot equal to
betweenBetween two values (must be integers)Find contacts whose Type is a value between 1 and 10:
<expr prop="Contact.Type" op="between">
<v>1</v>
<v>10</v>
</expr>
likeMatching a specified pattern. Accepts the wildcards % (for no, one or multiple characters) and _ (for only one character) in the v element. Note that your application is responsible for escaping special characters in the string value.Find contacts whose name starts with "A" followed by no, one or multiple characters:
<expr prop="Contact.Name" op="like">
<v>A%</v>
</expr>
containsContains a text stringFind contacts whose name contains the characters "abc" (in SQL syntax, this would be name like '%abc%'):
<expr prop="Contact.Name" op="contains">
<v>abc</v>
</expr>
startsStarts with a text stringFind contacts whose name begins with the letter "A" (in SQL syntax, this would be name like 'A%'):
<expr prop="Contact.Name" op="starts">
<v>A</v>
</expr>
endsEnds with a text stringFind contacts whose name ends with the letter "A" (in SQL syntax, this would be name like '%A'):
<expr prop="Contact.Name" op="ends">
<v>A</v>
</expr>
inTest if a property is from a list of values. Only simple type values are allowed.Find contacts who Type is 1, 2 or 3 (in SQL syntax, this would be type in (1,2,3)’):
<expr prop="Contact.Type" op="in">
<v>1</v>
<v>2</v>
<v>3</v>
</expr>
isnullIs null. Note that this operator takes no v element.Find contacts with no first name (in SQL syntax, this would be name is null):
<expr prop="Contact.FirstName" op="isnull" />
not-betweenNot between
not-inNot in
not-nullIs not null. Note that this operator takes no v element.
not-likeNot like
not-containsNot contains
not-startsNot starts
not-endsNot ends
anyAny of the child object matches with the given data (supported only by the sync operation’s logic_step condition.)

Functions


To refine a query, you can apply a function to a property by adding the fn attribute to the expr element. The following example uses the MONTH function to find contacts with a date of birth in March:


XML
<expr prop="Contact.Dob" op="eq" fn="MONTH">
  <v>3</v>
</expr>

SmartIntegrator supports only those SQL functions that are supported by the SmartOffice framework. The queried object must support the function in order for SmartIntegrator to return a result. Functions can only be applied to properties.


The available functions are:


  • YEAR
  • MONTH
  • DAY (Day of montth, i.e., 1–31)
  • HOUR
  • MINUTE
  • SECOND
  • QUARTER (Quarter of year)
  • WEEKOFYEAR (Week of year)
  • DAYOFYEAR
  • DAYOFWEEK
  • UCASE (Upper case)
  • LCASE (Lower case)

Child Object Properties


Searchable properties of child objects can also be specified in an expression. Relationships must be defined by the sub-type and foreign keys.


This sample expression looks for all contacts with a postal code of 91106.


XML
<expr prop="Contact.PreferredAddress.Postal" op="eq">
  <v>91106</v>
</expr>

Sort


The sort element defines the object property by which data returned by SmartIntegrator will be sorted. Only searchable properties can be sorted.


Within the sort element, use the item element with the following attributes to specify the sorting:


AttributeDescription
propThe name of a property. This is a short name and does not include an object name.
orderAccepts one of two values: asc (ascending) or desc (descending). The default is asc.

Example:


XML
<sort>
  <item prop="AreaCode" order="asc"/>
</sort>

Sorting is supported up to two levels of properties. For example:


XML
<sort>
  <item prop="Assignment.Contact" order="asc"/>
</sort>