Playing with Workday Studio MVEL type casting
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:
Text Only
// 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.
Text Only
// 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. 🤷
Text Only
// 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: