Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,296,425
Community Members
 
Community Events
165
Community Groups

Calculation between 2 custom fields (Probability x Impact)

Hello,
I hope you can help.
I have 2 custom fields (select list (single choice)) with values
Probability:

  • unspecified
  • very unlikely
  • unlikely
  • likely
  • very likely
  • almost certain

with values of
0 = unspecified
1 = very unlikely
2 = unlikely
3 = likely
4 = very likely
5 = almost certain

Impact

  • unspecified
  • insignificant
  • minor
  • moderate
  • major
  • catastrophic

with values of:
0 = unspecified
1 = insignificant
2 = minor
3 = moderate
4 = major
5 = catastrophic

I'm a complete novice to ScriptRunner but what I would like to see is

As an example:
from Probability - if I was to select 'unlikely' and from
from Impact - if I was to select 'moderate'

I would want the outcome of 6 (2 x 3) appearing as an integer in another custom field.

I would appreciate you r help in the resolution

 

Version of ScriptRunner: 5.6.1.1-jira8

Version of JIRA (server) 8.3.3

 

regards

Amrik

1 answer

1 accepted

0 votes
Answer accepted

Hi @Amrik Birdi

For your requirement, I would suggest using the Scripted Field. For more information, you can visit the ScriptRunner Documentation.

Also, please update the current version of ScriptRunner you are using to the latest release i.e. 6.28.0 as there been many bug fixes since the current version you are using.

Below is an example working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager

def probability = customFieldManager.getCustomFieldObjectsByName("Probability")[0]
def probabilityValue = issue.getCustomFieldValue(probability).toString()
def probabilityMap = ["Unspecified" : 1, "Very Unlikely" : 2, "Unlikely" : 3, "Likely" : 4, "Very Likely" : 5, "Almost Certain": 6]

def impact = customFieldManager.getCustomFieldObjectsByName("Impact Option")[0]
def impactValue = issue.getCustomFieldValue(impact).toString()
def impactMap = ["Unspecified" : 1, "Insignificant" : 2, "Minor" : 3, "Moderate" : 4, "Major" : 5, "Catastrophic": 6]

def probabilityNumber = 0
def impactNumber = 0

if(probabilityValue != "null" && impactValue != "null") {
probabilityNumber = probabilityMap.find{ it.key == probabilityValue }.value as Long
impactNumber = impactMap.find{ it.key == impactValue }.value as Long
}
return (probabilityNumber * impactNumber) as Long

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

To setup, the scripted field, go to the Fields option and select the Create Scripted Field option as shown below:-

image1.png

Next, select the Custom Script Field option as shown below:-

image2.png

Next, provide the Field Name you want to use and select the Number Field type as shown below:-

image3.png

Next, add the code to the script field and Update it as shown below:-

code_config.png

 

Below are a few tests:-

1) First, create an issue and select the values for the Probability and Impact lists and create the ticket as shown below:-

image5.png

2) The Scripted Field is only visible on the View Screen and not on the Create or Edit Screen. Once the issue has been created, the Scripted Field will display the output as shown below:-

image6.png

3) Try updating the Probability or Impact options, and you will see the Scripted Field will update as well as shown below:-

image7.png

image8.png

I hope this helps to solve your question. :)

Thank you and Kind Regards,

Ram

Hi Ram

thankyou so much in getting intouch with me but for some reason or another its not working for me.

Is it possible to tell me where i need to make the modifications?

 

kind regards

Amrik

Hi @Amrik Birdi

If you have just copied the code and pasted it in your environment, it will not work.

The differences that I have in my environment are

1) The Impact field in my environment is called Impact Option, as shown below:-

def impact = customFieldManager.getCustomFieldObjectsByName("Impact Option")[0]

 so you may need to rename the field in the code to match yours i.e.

def impact = customFieldManager.getCustomFieldObjectsByName("Impact")[0]

 2) The options from the list provided in the code contain Uppercase characters. However, in your description, you have only used lower case characters. You may want to take a look at that as well.

If you could share a print screen of your field configurations, i.e. for the Probability and the Impact field, it would be helpful.

 

Thank you and Kind Regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ many thanks for your answers. I have managed to modify accordingly

@Ram Kumar Aravindakshan _Adaptavist_ 

I tried your script but its not working for me

 

 

Hi @Akshith Kumar

Can you please share the script you are using? 

If you are getting any errors, please include the error logs that is being returned.

Also, please share a print screen of your fields configuration.

Thank you and Kind regards,

Ram

@Ram Kumar Aravindakshan _Adaptavist_ 

I have used the below script in RPN Script field let me know if I need to do any changes in the script

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager

def Impact = customFieldManager.getCustomFieldObjectsByName("Impact")[0]
def ImpactValue = issue.getCustomFieldValue(Impact).toString()
def ImpactMap = ["Not Applicable-0" : 0, "Insignificant-1" : 1, "Minor-2" : 2, "Minor-3" : 3,"Moderate-4" : 4, "Moderate-5" : 5, "Moderate-6": 6, "Major-7": 7, "Catastophic-8": 8, "Catastophic-9": 9, "Catastophic-10": 10]

def Likelihood = customFieldManager.getCustomFieldObjectsByName("Likelihood")[0]
def LikelihoodValue = issue.getCustomFieldValue(Likelihood).toString()
def LikelihoodMap = ["Not Applicable-0" : 0, "Rare-1" : 1, "Unlikely-2" : 2, "Unlikely-3" : 3, "Possible-4" : 4, "Possible-5" : 5, "Likely-6": 6, "Likely-7" : 7, "Certain-8" : 8, "Certain-9" : 9, "Certain-10" : 10]

def CounterMeasures = customFieldManager.getCustomFieldObjectsByName("Counter Measures")[0]
def CounterMeasuresValue = issue.getCustomFieldValue(CounterMeasures).toString()
def CounterMeasuresMap = ["Not Applicable-0" : 0, "Best in Class-1" : 1, "Strong-2" : 2, "Strong-3" : 3, "Average-4" : 4, "Average-5" : 5, "Average-6": 6, "Weak-7" : 7, "Weak-8" : 8, "Weak-9" : 9, "None-10" : 10]

def ImpactNumber = 0
def LikelihoodNumber = 0
def CounterMeasuresNumber = 0

if(ImpactValue != "null" && LikelihoodValue != "null" && CounterMeasuresValue != "null") {
ImpactNumber = ImpactMap.find{ it.key == ImpactValue }.value as Long
LikelihoodNumber = LikelihoodMap.find{ it.key == LikelihoodValue }.value as Long
CounterMeasuresNumber = CounterMeasuresMap.find{ it.key == CounterMeasuresValue }.value as Long
}
return (ImpactNumber * LikelihoodNumber * CounterMeasuresNumber ) as Long

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,557 views 37 45
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