I am trying to write a Groovy Script in Behaviours Plugin.
I have two Database Custom Fields, "Header Priority Value" and "SubHeader Priority Value".
I get the values 3.000000 and 2.000000 for these fields (Using SQL Query).
I have to add the values in those two fields and get the sum, and use that sum to set Priority.
This is the script i put on "SubHeader Priority Value" field:
FormField GV = getFieldById ("priority")
FormField HP = getFieldByName ("Header Priority Value")
FormField SHP = getFieldByName ("SubHeader Priority Value")
String HPV = HP.getValue()
String SHPV = SHP.getValue()
String PVSUM = HPV + SHPV
When i run this i am getting 3.0000002.000000 instead of 5.000000
I think this is because the values are considered as Strings. How do i do it ?
you're casting them to strings... try using
def HPV = HP.getValue()
if that doesn't work try casting to longs:
def HPV = HP.getValue() as Long
If they could be null try this:
def HPV = HP.getFormValue() ?: 0 def SHPV = SHP.getFormValue() ?: 0 def PVSUM = HPV + SHPV
Right now i have solved the problem by using only one field "SubHeader Priority Value" to determine the "Priority". But, i want to know how to add Numbers. So, This is the code i used: FormField GV = getFieldById ("priority") FormField HP = getFieldByName ("Header Priority Value") FormField SHP = getFieldByName ("SubHeader Priority Value") def HPV = HP.getValue() def SHPV = SHP.getValue() def PVSUM = HPV + SHPV log.error PVSUM And i got this: http-bio-8080-exec-13 ERROR uyadlapalli 801x8141x6 1bvbulw /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: (create issue) project/issuetype: TEST/Bug, user: uyadlapalli, fieldId: customfield_11703, file: <inline script> groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.util.json.JSONObject$Null.plus() is applicable for argument types: (com.atlassian.jira.util.json.JSONObject$Null) values: [null] Possible solutions: split(groovy.lang.Closure), is(java.lang.Object), use([Ljava.lang.Object;), wait(), grep(), find() at Script1.run(Script1.groovy:8)
Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs