Context expressions
You can use the following FEEL context expressions. Examples are provided to show common use cases.
Literal
Creates a new context with the given entries.
- Each entry has a key and a value.
- The key is either a name or a string.
- The value can be any type.
For valid key names, see naming conventions.
{
a: 1,
b: 2
}
// {a:1, b:2}
{
"a": 1,
"b": 2
}
// {a:1, b:2}
Inside the context, the previous entries can be accessed.
{
a: 2,
b: a * 2
}
// {a:2, b:4}
A context value can embed other context values.
{
a: 1,
b: {
c: 2
}
}
// {a:1, b:{c:2}}
Get entry/path
a.b
Accesses the entry with the key b
of the context a
. The path is separated by a dot .
.
If the value of the entry b
is also a context, the path can be chained (i.e. a.b.c
).
{a: 2}.a
// 2
{a: {b: 3}}.a
// {b: 3}
{a: {b: 3}}.a.b
// 3
If the context a
doesn't contain an entry with the key b
, the expression returns null
.
{a: 1}.b
// null
{a: 1}.b.c
// null
Filter
a[c]
Filters the list of context elements a
by the condition c
. The result of the expression is a
list that contains all elements where the condition c
evaluates to true
. The other elements are
excluded.
While filtering, the current element is assigned to the variable item
and its entries can be
accessed by their key.
[
{
a: "p1",
b: 5
},
{
a: "p2",
b: 10
}
][b > 7]
// [{a: "p2", b: 10}]
Projection
a.b
Extracts the entries with the key b
of the list of context elements a
(that is, a projection). It returns a list containing the values of the context elements with the key b
.
[
{
a: "p1",
b: 5
},
{
a: "p2",
b: 10
}
].a
// ["p1", "p2"]
If an element of the list a
doesn't contain an entry with the key b
, the result contains null
of this element.
[
{
a: "p1",
b: 5
},
{
a: "p2",
c: 20
}
].b
// [5, null]
Examples
Validate data
Validate journal entries and return all violations.
{
check1: {
error: "Document Type invalid for current year posting",
violations: collection[documentType = "S2" and glDate > startFiscalYear]
},
check2: {
error: "Document Type invalid for current year posting",
violations: collection[ledgerType = "GP" and foreignAmount != null]
},
result: [check1, check2][count(violations) > 0]
}
Structure calculation
Calculate the minimum age of a given list of birthdays.
{
age: function(birthday) (today() - birthday).years,
ages: for birthday in birthdays return age(birthday),
minAge: min(ages)
}.minAge