Playing with Workday Studio MVEL type casting
Posted 3Â months ago
MVEL uses implicit type conversion, so it will automatically attempt to determine and set the type of your variable or property. Usually that's okay, but if you want to change or explicitly set the type, here's some examples:
Getting the type
If you need to identify the type of something. Use .getClass().getName()
. Example:
// Get a launch parameter as-is
props['delay'] = lp.getSimpleData('delay')
// Get the type
props['delay_type'] = props['delay'].getClass().getName()
Output in a message:
Delay set to 154.123 seconds. Type: java.lang.String
Type casting to double
Similar steps, but as a double type.
// Get a launch parameter and cast to double
props['delay'] = (double)lp.getSimpleData('delay')
// Get the type
props['delay_type'] = props['delay'].getClass().getName()
Output in a message:
Delay set to 154.123 seconds. Type: class java.lang.Double
Type casting to integer
For some reason the conversion fails without first casting to double. 🤷
// Get a launch parameter and cast to double
props['delay'] = (double)lp.getSimpleData('delay')
// Cast to string
props['delay'] = (int)props['delay']
// Get the type
props['delay_type'] = props['delay'].getClass().getName()
Output in a message:
Delay set to 154 seconds. Type: java.lang.Integer
Type casting validation expressions
Example:
// Make sure the delay time is less than 1 hour
props['delay'] < (int)(60*60)