Universal Search Filter Syntax: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
Tag: 2017 source edit
mNo edit summary
Tag: 2017 source edit
Line 1: Line 1:
<!-- BEGIN origin interlang links -->
<!-- You can edit this section but do NOT remove these comments
    Links below will be automatically replicated on translated pages by PolyglotBot -->
<!-- END interlang links -->
[[Category:Admin_en]]
{{TemplateDocDevEn}}
The Universal Search Filter (also mentioned as USF) is the technical syntax to use in Dolibarr to define a filter.
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:
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)
* build rules to filter some combo list when the define an object dataset (into the property ->fields of an object)
Line 5: Line 16:
* to provide filters to some Ajax components.
* to provide filters to some Ajax components.
* It is also used to add a filter on some requests on APIs.
* It is also used to add a filter on some requests on APIs.
= 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:
<syntaxhighlight>
(myfield:=:'mystringvalue')
(myfield:>=:123.45)
(myfield:>:'2024-01-01 10:00:00')
</syntaxhighlight>
Example of combined tests:
<syntaxhighlight>
((myfield:=:'mystringvalue') OR ((myfield:>=:myintorfloatvalue) AND (myfield:>:'2024-01-01 10:00:00')))
</syntaxhighlight>

Navigation menu