Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner strange behavior

Hi, 

I have field1 and fieild2 on my issue ticket.

I try to use the script runner to do a simple action that raises an error when the user edit field1 with value that higher then field2 with the next code:

if (getActionName() == null){ //check that we are on edit screen
def field1 = getFieldByName("Paid Assets/Apps")
def fieild2 = getFieldByName("Planned Assets/Apps")
if (field1.getValue() < fieild2.getValue())
{
fieild2.setError("fieild1 can not be lower than fieild2")
}
else {
fieild2.clearError()
}

 

Seems it works and the error raising - SOMETIMES.

When field1 = 100 field2 = 10 everything OK, but

when field1 = 100 field2 = 20 (or each another number without any consistent) the ERROR raised without any reason (field1 > field2 as it should)

image.pngimage.png

I get crazy from that unexplained BUG. 

Hope for help ! :)

 

1 answer

1 accepted

0 votes
Answer accepted

Hello,

What are the field types?

You can add logging to see the class of the returned values. Maybe it returns String or something like this:

if (getActionName() == null){ //check that we are on edit screen
def field1 = getFieldByName("Paid Assets/Apps")
def fieild2 = getFieldByName("Planned Assets/Apps")
log.error("field1.getValue(): ${field1.getValue().getClass()}")
log.error("field2.getValue(): ${field2.getValue().getClass()}")
if (field1.getValue() < fieild2.getValue())
{
fieild2.setError("fieild1 can not be lower than fieild2")
}
else {
fieild2.clearError()
}

Hi,

They're both 'Number Field'

You were right, the value that I get from those are 'String'
Thank you !

Did you find the class of each variable in the log file?

You are welcome!

Yes, they were String class, I had to parse them to Int for comparing.

@Daniel Juravski how did you parse the string value to Int in script runner behaviors?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

How to log work and track time in Jira when a person is part of multiple teams

  The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...

85 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you