This page provides reference and examples of how to write flex expressions based on the SpEL language.

General SpEL expression language overview

In general ROB-EX Scheduler flex expressions are SpEL expression with a few ROB-EX Scheduler specific extensions added. The SpEL language was originally developed as an internal utility of the Spring server framework, but has proven to be efficient also for more general purpose functionality. The internet has a wealth of learning material regardng SpEL – try a search like this.

SpEL operators

Type Operators
Arithmetic +, -, *, /, %, ^, div, mod
Relational <, >, ==, !=, <=, >=, lt, gt, eq, ne, le, ge
Logical and, or, not, &&, ||, !
Conditional ?:
Regex matches

Examples using operator

Arithmetic examples.

19 + 1 : 20
'String1 ' + 'string2' : “String1 string2”
20 - 1 : 19
10 * 2 : 20
36 / 2 : 19
37 % 10 : 7
2 ^ 9 : 512
(2 + 2) * 2 + 9 : 17

Relational examples.

1 == 1 : true
1 != 1 : false
1 < 1 : false
1 <= 1 : true
1 > 1 : false
1 >= 1 : true

Logical examples.

250 > 200 && 200 < 4000 : true
250 > 200 and 200 < 4000 : true
400 > 300 || 150 < 100 : true
!true : false

Conditional examples.

2 > 1 ? 'a' : 'b' : “a”
someBean.someProperty != null ? someBean.someProperty : 'default'

Regular expresion matching examples

'100' matches '\\d+' : true
100fghdjf' matches '\\d+' : false
'valid alphabetic string' matches '[a-zA-Z\\s]+' : true
'invalid alphabetic string #$1' matches '[a-zA-Z\\s]+' : false
someBean.someValue matches '\d+' : true if someValue contains only digits

ROB-EX Scheduler utility methods and context. Notice the use of the matches keyword, when matching on regular expressions.

This is a list of SpEL functions that are specific for ROB-EX Scheduler. They provide access mainly to values returned by existing layout items. Using a layout item is a convenient way of getting the value of a field, without knowing the API level name of the field.

The input variable refers to the input object passed in by the system when the expression is called. Not that this is a standard ROB-EX Scheduler base model object like e.g. Operation, ProductionOrder etc. You can call any public method on these objects. If the Operation object has a getName() API method, then you can call input.name to access the value of this name field.
You can freely choose to use the short or Long name version of the function call. The long name version is provided as it is more self-explainable when viewed by a new SpEL programmer.

Function Long name Return type Description Example
fv(String id) flexValue Object id: field id of a layout item.
The layout item is looked up and applied to the input object, passed into the expression by the system. The return value depends on the layout item called
fv("order_delivery_exceeded")

If the input type is operation the expression invokes the order_delivery_exceeded layout item on the operation, which returns a true/false value.
fv(String id, Object in) flexValue Object Is similar to flexValue(String id), but takes two parameters.
id: field id of a layout item in: the input object.
The layout item is looked up and applied to the input object. The return value depends on the layout item called
fv("resource_capacity", input.selectedResource)

If the input type is operation the expression invokes the resource_capacity layout item on the resource the input operation is assigned to, which returns a Number value.
fvNum(String id) flexValueAsNumber Number Works exactly like flexValue(String id) only it will throw an error, if the layout item does not return a number.
fvNum(String id, Object in) flexValueAsNumber Number Works exactly like flexValue(String id, Object in) only it will throw an error, if the layout item does not return a number.
fvStr(String id) flexValueAsString String Works exactly like flexValue(String id) only it will throw an error, if the layout item does not return a string.
fvStr(String id, Object in) flexValueAsString String Works exactly like flexValue(String id, Object in) only it will throw an error, if the layout item does not return a string.
format(String partern, Object ... values) String passes the parameters to the java.lang.String.format method. format('%.3f', input.workload)

Formats the workload to 3 decimals places.

Different examples

Input type: OPERATION

Example 1: input.operationSequence?.name=='104'
Navigate from operation to route (operation sequence) name
Example 2: input.productionOrder?.name=='33'
Navigate from operation to production order name
Example 3: input.customText1 ?:'is null'
Example of using the ‘Elvis operator’ ?:. This is a conditional expression returning the parameter value, unless it is null. When null the value after ?: is returned – in the example the text string 'is null'.
Example 4: input.operationSequence?.operationList[0].name=='Cutting'
Navigate from operation to route (operation sequence) and evaluate the name of the first operation (at index 0) in the route. Note error is thrown if the route does not have at least one operation
Example 5: input.operationSequence?.operationList.^[name == 'Cutting'].id
Example of using the Collection Selection instruction ^[] which will return the first object in a list with an attribute that matches the specified criteria. In this case we return the string id of first operation in the route having the name ‘Cutting’.
Example 6: 'oprStart=' + input.getEnd().toString('yyyy-MM-dd HH:mm') + " oprEnd=" + input.getStart().toString('yyyy-MM-dd HH:mm') + " orderDelivery=" + input.getProductionOrder().getEnd().toString('yyyy-MM-dd HH:mm')
Example of getting and formatting operation and order dates. For additional date formatting, see options here.
Example 7: fv('order_product_id')?.substring(0, fv('order_product_id').length() < 8 ? fv('order_product_id').length(): 8)
Example of getting leftmost 8 characters of the order item no. It does unfortunately get quite long and complex as there is no convenience method available for this.
Example 8: (input.customText4?:"") matches '(?i).*complete.*'
Example of returning “true” or “false” based on if operation.customText4 contains the word “complete” or not. The search is carried out using a regular expression (the matches operator) because this way the search can be made case insensitive, by using the regular expression control (?i) . Also note the usage of the elvis operator ?: in order to cope with null values in operation.customText4

Input type: OPERATION_AND_RESOURCE

Example 1: input.operation or input.getOperation()
Get the operation from the OperationAndResource input type
Example 2: input.resource or input.getResource()
Get the resource from the OperationAndResource input type

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment