You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
I'm hoping somebody can help with this.
I'm pretty new to scriptrunner and trying to adjust Custom Field behaviour based on the numeric value of a field being over a certain amount.
I have done this previously in the attached picture using field dropdown options but, it would be great if there was a similar way I could do this based on numeric Value.
Thanks,
Jonny
Hi @jonny.smith ,
This is absolutely possible. A number field will return a double, meaning you could use :
def numField = getFieldByName("Number Field")
def numFieldValue = numField.getValue()
if (numFieldValue == 10) { ... }
if (numFieldValue > 10) { ... }
Is this what you are asking for ?
Hi @Antoine Berry ,
It looks like it should do what I'm after however, I seem to be getting the following errors on the 'if' lines.
Thanks,
Jonny
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jonny.smith ,
This error will be corrected at execution time. This is because you have not declared numFiledValue as a Double. But it is not necessary in groovy and the comparison will succeed at execution time. To make sure it not throwing any error you could use this instead :
Double numFieldValue = numField.getValue()
if (numFieldValue && numFieldValue > 20.00) { ... }
This way the console will declare the value as a double and will check that it has a value (i.e. you have filled a value on the screen and therefore is not null) before comparing to 20.00.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think @Antoine Berry covered most of it... but I notices you have 2 identical if blocks.
That's not necessary. The curly brace indicates a code block that can have multiple lines such as:
def numField = getFieldByName("Total Amount")
def numFieldValue = numField.getValue()
def field1 = getFieldByName("Attachment")
if (numFieldValue > 20.00) {
field1.setHidden(false)
field1.setRequired(true)
}
Or in this case, you can even string those two:
field1.setHidden(false).setRequired(true)
But I noticed that you don't have a block of code to hide again if the number is smaller.
This would combine all of the above:
def numField = getFieldByName("Total Amount")
def numFieldValue = numField.getValue()
def field1 = getFieldByName("Attachment")
def isBigAmount = numFieldValue > 20.00
field1.setHidden(!isBigAmount).setRequired(isBigAmount)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry @Peter-Dave Sheehan ,
I have tried out both of these this morning and they both work as required! I've opted to just use the setRequired functionality so the team still have the ability to upload an attachment for under 20.00 if they want to.
Really appreciate the help!
Thanks,
Jonny
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.