Hello,
I hope you can help.
I have 2 custom fields (select list (single choice)) with values
Probability:
with values of
0 = unspecified
1 = very unlikely
2 = unlikely
3 = likely
4 = very likely
5 = almost certain
Impact
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
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:-
Next, select the Custom Script Field option as shown below:-
Next, provide the Field Name you want to use and select the Number Field type as shown below:-
Next, add the code to the script field and Update it as shown below:-
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:-
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:-
3) Try updating the Probability or Impact options, and you will see the Scripted Field will update as well as shown below:-
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ many thanks for your answers. I have managed to modify accordingly
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.
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
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.
@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
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.