name = $c:account/c:attributes/ri:uid
Using expressions in midPoint Query Language
Since 4.5This functionality is available since version 4.5.
MidPoint Query Language provides special syntax support for most common expression types.
|Expressions are not executed / supported for user entered queries in search box in midPoint GUI, since that would allow users to execute code and may pose additional security risks.|
Script expressions are supported for following filters:
Value comparison filters
The syntax for path expression is pretty straight-forward, since most path expression references variable.
Variables start with dollar
$ symbol. Note that variables are only supported
as right-hand side value.
<q:equal> <q:path>name</q:path> <c:expression> <c:path>$c:account/c:attributes/ri:uid</c:path> </c:expression> </q:equal>
There are two syntax options for script expression: single-line scripts and multi-line scripts. By default, scripts are Groovy scripts unless other scripting language is specified.
metadata/createTimestamp > `basic.fromNow("-P30D")`
Single-line expressions are written as strings surrounded with single
character. This allows you to use quotes inside script without need to escape them.
metadata/createTimestamp > ``` now = basic.currentDateTime(); ret = basic.addDuration(now, "-P30D"); return ret ```
The syntax for multi-line expressions is a bit more elaborated, multi-line script
starts with triple backticks (
```), followed by new-line.
Script body is closed by triple backticks (
```). This minimizes
need for escaping most of the quotes or sequences inside the script body.
|Script expressions are not allowed in search box in GUI.|
Other Scripting languages
You can use other supported scripting language for expressions, by prefixing quotes with language name e.g.:
metadata/createTimestamp > groovy`basic.fromNow("-P30D")`
The language name is same as you would use in XML filter script expressions.
Other expression types
If you plan to use expression type, which does not have simplified syntax,
you can use
yaml expression (
yaml language is only available in midPoint queries).
yaml expression allows you to pass-thru standard
serialized in YAML format.
This is useful, if you need to define additional properties of expression, or use other expression types, which does not have built-in syntax support.
metadata/createTimestamp > yaml``` script: language: groovy code: | now = basic.currentDateTime(); ret = basic.addDuration(now, "-P30D"); return ret ```
<filter> <gt> <path>metadata/createTimestamp</path> <expression> <script> <language>groovy</language> <code> ret = basic.addDuration(now, "-P30D"); now = basic.currentDateTime(); return ret </code> </script> </expression> </gt> </filter>
In midPoint 4.5 and 4.6 you have to indent the content of the YAML expression with at least one space, otherwise it will not parse with quite an obscure error.
Expressions in general