Log In
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
  [Expand]Application Solution Components
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Extend Functionality
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]System Module
  [Expand]Extra Modules
  [Expand]Debugging and Error Handling
    Criteria Property of a List View's Collection Source
    Criteria Property in the Application Model
    Filters Application Model Node
    ListViewFilter Attribute
    FullTextSearch Action
    UI-Specific Filtering Techniques
    DataSourceProperty, DataSourceCriteria and DataSourceCriteriaProperty Attributes
    Ways to Build Criteria
    Object Parameters
    Current Object Parameter
    Function Criteria Operators
    Custom Function Criteria Operators
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Functional Testing
 [Expand]Task-Based Help
 [Expand]Frequently Asked Questions
 [Expand]API Reference
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
[Expand]End-User Documentation

Function Criteria Operators

The eXpressApp Framework provides various approaches to filter List Views: on a data source level, via the Application Model and special methods for filtering the List Views of Lookup Property Editors. In addition, filtering is also required when you are generating reports on business objects. In each of these approaches, you may need to set static variables as filter criteria values. For example, the filter "Task.DueDate must be set to the current date" needs the CurrentDate variable, calculated every time it is required. For this purpose, you should use Function Criteria Operators. They represent functions you can use in criteria. These can be functions that simply return a value, such as the current date or the current user. They can also represent functions that take arguments, such as the concatenation function. This topic explains the basics of Function Criteria Operators, and shows how to use them when filtering. In addition, you will learn how to implement Custom Function Operators.

Expanded Function Criteria Operators Basics

Function Criteria Operators are a part of the criteria language. To learn more about the language, refer to the Criteria Language Syntax help topic. In criteria strings, a Function Criteria Operator name must be followed by brackets containing operands representing function arguments. If a Function Criteria Operator does not take arguments, empty brackets should be specified. The following criteria demonstrate usage of the LocalDateTimeToday Operator.

[Task.DueDate] = LocalDateTimeToday()

There are more than a hundred Function Criteria Operators available out of the box, such as LocalDateTimeAfterTomorrow or Replace. For a complete list, refer to the FunctionOperatorType help topic. There are also XAF-specific Function Criteria Operators available in all XAF applications. The following table lists them.

CurrentUserId() Returns the identifier of the current user registered by the Security System. This custom Function Criteria Operator is registered in the ModuleBase.CustomizeTypesInfo method override of SystemModule. The Evaluate method of this Operator simply returns the SecuritySystem.CurrentUserId property value. User.Oid = CurrentUserId()
IsCurrentUserInRole(roleName) Determines whether the currently logged on user is assigned a specified role. Returns false when there is no currently logged on user. This custom Function Criteria Operator is registered in the XafApplication.LoggedOn event handler by the SecurityModule if SecuritySystem.CurrentUser implements the IUserWithRoles or ISecurityUserWithRoles interfaces. The Evaluate method of this Operator casts the SecuritySystem.CurrentUser property value to the IUserWithRoles and ISecurityUserWithRoles interfaces and checks that the Roles collection contains the specified role. IsCurrentUserInRole('Admin')
IsNewObject(obj) Applicable to XPO objects only. Indicates whether a specified object has been created but has not been saved to the database. The Evaluate method of this operator gets the current Object Space via the static XPObjectSpace.FindObjectSpaceByObject method and then returns the XPObjectSpace.IsNewObject result. In case the Object Space is not found, returns false. Can be evaluated at the client side only. Should not be used in security permissions criteria. IsNewObject(This) IsNewObject(Manager)

Expanded Important Remark on the DateTime Function Criteria Operators

The addition and subtraction operations are not supported for the DateTime parameters. So, in general, the following expression is incorrect:

[Task.DueDate] > (LocalDateTimeToday() - 3) AND [Task.DueDate] < (LocalDateTimeToday() + 3)

To add or subtract values to the DateTime parameters, use the DateTime management functions exposed by the XPO, such as the AddDays and AddYears functions. For a complete list of functions with descriptions, refer to the Criteria Language Syntax help topic. For instance, the previous criteria are correctly written like this:

[Task.DueDate] > ADDDAYS(LocalDateTimeToday(), -3) AND [Task.DueDate] < ADDDAYS(LocalDateTimeToday(), 3)

Certain database management systems (DBMS) support plain addition and subtraction operations for the DateTime parameters. When such an expression is evaluated on the server side, there will be no errors. For example, when filtering a List View via the ListViewFilterAttribute, the criterion is processed on the server. If the server supports addition and subtraction operations for the DateTime parameters (e.g. MS SQL Server or MS Jet Database Engine) the criterion will be correctly processed, and no errors will occur.

Expanded See Also

How would you rate this topic?​​​​​​​