Universal Search Filter Syntax

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search


The Universal Search Filter (also mentioned as USF) is the technical syntax to use in Dolibarr to define a filter.

When to use the UFS

It is used by developers to:

  • build rules to filter some combo list when the define an object dataset (into the property ->fields of an object)
  • to provide filters to some functions and methods in Dolibarr into internal code code.
  • to provide filters to some Ajax components.
  • to define filters on some requests on APIs.
  • to propagate securely filters, for example in the customreport.php tools.

Why to use the UFS

The UFS syntax has been introduced for two main reason:

  • To allow to provide a secured way to propagate a filter from a component to another one, with no risk of injections
  • To provide a generic solution to define a filter that follows structured rules making possible to convert it easily and programmaticaly into the expected language, whatever is this language (most often in SQL but also in PHP or Javascript).

Syntax of UFS

A simple test in UFS syntax is forged this way: Open parenthesis, then the first operand that is the field, then :, then the operator, then :, then the second operand that is the value, then the closing parenthesis.

The operator can be =, <, >, <=, >=, !=, in, notin, like, notlike, and nothing else.

If the value is a string, you must add simple quotes. If value is a date, it must used the international format and be quotes too.

Then, you can combine any simple test using parenthesis and OR or AND to forge combined tests.

Example of simple tests:

(myfield:=:'mystringvalue')
(myfield:>=:123.45)
(myfield:>:'2024-01-01 10:00:00')

Example of combined tests:

((myfield:=:'mystringvalue') OR ((myfield:>=:myintorfloatvalue) AND (myfield:>:'2024-01-01 10:00:00')))