Other Operators
With the following, additional operators you can customize your model even further.
FILTER
The FILTER
operator is used to filter documents referenced by a dynamic value in a reference field. It allows the administrator to find the right document based on a filter rather than having to find out the exact _id
of that document. Note: This operator is often used together with the
INDEX operator.
Syntax
FILTER(document-definition, query, projection-field-name)
Parameters:
-
document-definition - The name of the document definition from which the document should be found.
-
query - The query to filter the documents by. This should be a filter expression.
-
projection-field-name - [ OPTIONAL ] - The name of the field which will be returned for each entity that passes the filter. Can be an expression that must resolve to a string. Default to
_id
.
Examples
FILTER("items","code = 500")
returns an array of documents (can also be just one document) for which the "code" field equals "500".FILTER("items","code = 500 AND stock > 100")
returns the document for which the "code" field equals "500" and the "stock" field is greater than 100.FILTER("items","code = 500", "code")
returns an array of "code" strings, one for each document where "code" field equals "500".FILTER("items","code = 500", IF(USER["administrator"], "code", "name"))
returns an array of "code" strings if the user is administrator or an array of "name" strings otherwise, one for each document where "code" field equals "500".
FORMAT
The FORMAT
operator changes the format of an input. These can either be number, time, date, or string inputs. This operator can, for example, format the input as follows:
Parameters:
- Date - 'YYYY-MM-DD', 'MM-DD-YYYY', 'DD-MM-YYYY', 'Do:MM:YYYY', 'DD/MM/YY'
- Time - 'HH:mm'
- Date-time - 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'
- Text - 'camelCase', 'snakeCase', 'kebabCase', 'trim'
For formatting date values, Day.js is used.
For formatting number values, Numeral.js is used.
Syntax
FORMAT(expression, format)
Parameters:
-
expression - An expression or pointer to a field.
-
format - The format that should be applied to the expression parameter.
Examples
FORMAT(F["date"],"Do:MM:YYYY")
returns the value of the "date" field like "20th:02:1993".FORMAT("2024-01-01","DD-MM-YYYY")
returns a date like "01-01-2024".FORMAT(F["time"],"h:m")
returns the value of a "time" filed like "12:45".FORMAT(F["time"],"")
returns the value of a "time" field like "12:45 PM".FORMAT(F["time"],"minutes")
returns the value of a "time" field as a number of minutes. 12:45, for instance, would return "765".FORMAT(L["lines"][0].F["duration"], "hours")
returns the value of the "duration" field in the lines line block as a number of hours. 12:45, for instance, would return "12,75".FORMAT(F["dateTime"],"LLL")
returns the value of the "dateTime" field like "March 18, 2023 2:05 PM".FORMAT(F["number"],"0.00")
returns the value of the "number" field like "1.00".FORMAT(F["float"],"$0.0")
returns the value of the "float" field like "$2,5".
LABEL Operator
The LABEL
operator is used to get the label value of a status in the document definition instead of its name. If another field is used in combination with this operator it will resolve to the value of that field.
Syntax
LABEL(pointer)
- pointer - A pointer to a field, usually the status field.
Examples
LABEL(F["status"])
returns the label value of the status (e.g. "Active" instead of "1000").
SETVALUES
As the name indicates, the SETVALUES
operator is used to set values of fields in a document. The SETVALUES
operator can only be used in the Set Field Value rule.
Syntax
SETVALUES(array-expression1, array-expression2...)
Parameters:
-
array-expression1 - An array that contains two values: a pointer and a value.
-
array-expression2, ... - [ OPTIONAL ] - Additional arrays that all contain two values: a pointer and a value.
Examples
SETVALUES([ F["name"], "BizzStream" ])
sets the value of the "name" field to "BizzStream".SETVALUES([ F["name"], "BizzStream" ], [ F["amount"], 100])
sets the value of the "name" and "amount" fields to "BizzStream" and 100 respectively.SETVALUES([ F["total], F["price"] * F["quantity"] ])
sets the value of the "total" field to 10 if the value of the "price" field is 5 and the value of the "quantity" field is 2.