Hi!
I'm having trouble with server-side script in SR Behaviors. Any help would be greatly appreciated.
Requirement:
- After value added to Numeric Custom field, check expression
- If the value doesn't match local number format (russian), try simple transformations to rectify most regular mistakes (usual for copy-paste):
- Delete spaces (thousands separators, extra symbols at the start or the end)
- Replace "." with ","
Local number format:
- Correct value: ####,## (i.e. 150345,53) (please note the comma, it plays a role)
Code:
def revField = getFieldByName("My numeric CF")
def revFieldCurValue = revField.getValue().toString()
if (!revFieldCurValue.matches("[0-9]*(|[0-9]*,[0-9]{2})") && !revFieldCurValue.matches("[0-9]*(|[0-9]*,[0-9]{1})") && !revFieldCurValue.matches("[0-9]*")) {
log.warn("Fire!")
def revFieldNewValue = revFieldCurValue.replace(" ", "")
revFieldNewValue = revFieldNewValue.replace(".", ",")
revField.setFormValue(Long.valueOf(revFieldNewValue))
}
The problem is that <getValue()> returns "null" in my instance.
Even more frustrating is that "null" returns even if the value is correct, but it has decimals (which separated by comma)!
For example, correct format of value "10000,00" gets null. But "10000" gets "10000.0".
Is there a way to retrieve value initially with transformation from local format to long or to string?
Or may be there is a completely different way to achieve the same thing (requirement-wise)?