I want calculate a score based on selection of different fields.
Here is the scenario
I have few drop down fields and radio button fields ( custom fields), each selection has a value to it.
based on selection, it should calculate value and shown in "Score" - custom field.
e.g.
1, radio button field: for option "yes" - value - 4
for option "no" - value - 0
2. drop down field : for option 1 - value - 5
for option 2 - value 5
for option 3 - value 4
for option 4 - value 4
3. drop down field : for option 1 - value 5
for option 2 - value 4
..
.
.
likewise 5 dropdown fields with multiple options and values for those.
after selecting all above fields, my score field should show ( addition of values of selected options)
Can somebody help me with code or guide me the correct plugin for this?
Thanks and appreciate your help.
Community moderators have prevented the ability to post new answers.
Hi Raj,
here code for your scripted field :
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.fields.CustomField; Issue issue = issue; CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField radio = customFieldManager.getCustomFieldObjectByName("Radio Field Name"); CustomField customField1 = customFieldManager.getCustomFieldObjectByName("Drop down Field Name 1"); CustomField customField2 = customFieldManager.getCustomFieldObjectByName("Drop down Field Name 2"); Integer result = new Integer(0); if(issue.getCustomFieldValue(radio)!=null){ if("yes".equalsIgnoreCase(issue.getCustomFieldValue(radio).toString())){ result = result + 4; } } if(issue.getCustomFieldValue(customField1)!=null){ if("option name 1".equalsIgnoreCase(issue.getCustomFieldValue(customField1).toString()) || "option name 2".equalsIgnoreCase(issue.getCustomFieldValue(customField1).toString()) ){ result = result + 5; } else { if("option name 3".equalsIgnoreCase(issue.getCustomFieldValue(radio).toString()) || "option name 4".equalsIgnoreCase(issue.getCustomFieldValue(radio).toString()) ){ result = result + 4; } } } if(issue.getCustomFieldValue(customField2)!=null){ if("option name 1".equalsIgnoreCase(issue.getCustomFieldValue(customField2).toString())){ result = result + 5; } else { if("option name 2".equalsIgnoreCase(issue.getCustomFieldValue(customField2).toString())){ result = result + 4; } } } return result;
Hope this helps.
Please change option name and custom field name at your convenience. Use "Script Runner" plugin that allows you to define a scripted field.
Regards,
Fabio
Fabio
thank you so much, it is working great, i need to add some more options and test it out, appreciate your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio
when i have the "$" in the name of custom field or option values, i am getting error.
for option values i am putting backward slash "over \$500k" is this ok?
how to avoid this error? appreciate your help.
- javax.script.ScriptException: java.lang.NullPointerException A stacktrace has been logged.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raj,
try to use "\u0024" instead of "$". Let me know if it fixs your issue.
Regrds,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
\$ should be fine... any reason to use the unicode char over \$ ? The latter is clearer to me.
You can use single quotes if you don't want interpolation - either of these should work:
"\$5" or '$5'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio
It did not help, i have removed $ sign from custom field name and options, still i am getting same error, did reindex also, still no use.
when i remove code for that field, remaining code is working great.
thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie
\$ is working fine, as suggested in warning message!
My issue is : one custom field is giving NullPointer exception, previously it had $ in the name and options, i removed $ in all, still error is coming!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Raj,
please could you post the whole script code? I could try to figure out the problem.
Regrds,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all your help, reindexing did not help, somehow old value with '$' residing somewhere, so i had to put back $ with \$, now it is working fine, thanks for all your help. appreciate it.
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.