Hello,
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
log.error PVSUM
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()
etc
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
I tried 'def' but got an error. I will try to Cast it as Long and see if it works. Thank You.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't see how you can have got an error... paste the full minimal code and include the error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
looks like one or both is null, check my updated answer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes Jamie. They will be Null initially. Thank you. That Works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.