Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve value of numeric Custom field in SR Behaviors

Alex Trebek
Contributor
May 18, 2021

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)?

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 23, 2021

Hi @Alex Trebek,

Currently, the format of the Number Field that you are trying to configure is not supported by Jira; hence it's not doable in ScriptRunner.

Please visit this Atlassian Jira Ticket for more information.

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer