Need to Multiply 3 Custom field values in another Custom Field

Akshith Kumar March 23, 2022

Custom Field 1 - Impact

Not Applicable-0
Insignificant-1
Minor-2
Minor-3
Moderate-4
Moderate-5
Moderate-6
Major-7
Catastophic-8
Catastophic-9
Catastophic-10

Custom Field 2 - Likelihood

  • Not Applicable-0
  • Rare-1
  • Unlikely-2
  • Unlikely-3
  • Possible-4
  • Possible-5
  • Likely-6
  • Likely-7
  • Certain-8
  • Certain-9
  • Certain-10

Custom Field 3 - Counter Measures

  • Not Applicable-0
  • Best in Class-1
  • Strong-2
  • Strong-3
  • Average-4
  • Average-5
  • Average-6
  • Weak-7
  • Weak-8
  • Weak-9
  • None-10

    Custom field 4 - RPN

    So first three are single select list custom fields

    Custom Field 4 = Custom Field 1 * Custom Field 2 * Custom Field 3
    I.E RPN = Impact * Likelihood * Counter Measures

    Can someone help me to do this In Jira Data Center?

3 answers

1 accepted

1 vote
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Hi @Akshith Kumar 

As of my understanding, these are single-select custom fields and you need to convert them into numbers based on their values: e.g. Catastophic-8 is equal to "8", then multiply all three fields and set it to a number field which is customfield4.

Is that what you want?

Akshith Kumar March 24, 2022

Exactly

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

This might be a good starting point,

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager


def cf1 = customFieldManager.getCustomFieldObject(id1) // id of the CF1
def cf2 = customFieldManager.getCustomFieldObject(id2) // id of the CF2
def cf3 = customFieldManager.getCustomFieldObject(id3) // id of the CF3
def cf4 = customFieldManager.getCustomFieldObject(id4) // id of the CF4 (multiplication result)

def cf1Value = issue.getCustomFieldValue(cf1).toString()
def cf1IntValue = cf1Value.substring(cf1Value.lastIndexOf("-") + 1, cf1Value.length()) as int

def cf2Value = issue.getCustomFieldValue(cf2).toString()
def cf2IntValue = cf2Value.substring(cf2Value.lastIndexOf("-") + 1, cf2Value.length()) as int

def cf3Value = issue.getCustomFieldValue(cf3).toString()
def cf3IntValue = cf2Value.substring(cf3Value.lastIndexOf("-") + 1, cf3Value.length()) as int

int cf4Value = cf1IntValue * cf2IntValue * cf3IntValue

issue.setCustomFieldValue(cf4,cf4Value)
Akshith Kumar March 24, 2022

error.PNG

Akshith Kumar March 24, 2022

there are some errors in the code can you look in to this and suggest changes?

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

You can't use space characters in your variable definition.

Simply change all "Counter MeasuresValue" to "CounterMeasuresValue" , etc..

Akshith Kumar March 24, 2022

but even our custom field has a space does it work if I write the code with out a space?

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Yes, it will work. This is just the variable name, it does not need to be the same as the custom field name.

Like Akshith Kumar likes this
Akshith Kumar March 24, 2022

still there is an error in the last line

Akshith Kumar March 24, 2022

errorrr.PNG

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Can you please try this?

MutableIssue missue = (MutableIssue) issue
missue.setCustomFieldValue(RPN,RPNValue)
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Don't forget to add this import statement to the top line

import com.atlassian.jira.issue.MutableIssue
Akshith Kumar March 24, 2022

No errors now but it only displays null values with out any error in log

Akshith Kumar March 24, 2022

preview.PNG

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Have you checked the issue if it was updated?

Since your code does not return anything, it is normal to see null in the Result section.

Akshith Kumar March 24, 2022

Yes i tried creating new issues as well still no results

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Is this post function? Where are you using this script?

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

By the way, you can add log.error lines to see whether your calculations are OK.

 

log.error("ImpactIntValue: $ImpactIntValue")

log.error("LikelihoodIntValue: $LikelihoodIntValue")

etc.

You will see the logs in the Logs section

Akshith Kumar March 24, 2022

i am using this script in script runner numeric field

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 24, 2022

Did you share a link?

Anyway, I think you are using a scripted field.

Then please skip the last line

issue.setCustomFieldValue(RPN,RPNValue)

instead, use this 

return RPNValue
Like Akshith Kumar likes this
Akshith Kumar March 24, 2022

Thank you so much for your help Final It worked for me :D

0 votes
Akshith Kumar March 24, 2022

@Ram Kumar Aravindakshan _Adaptavist_ Can you provide me the script based on this?

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2022

What scripting/automation apps do you have available?

Akshith Kumar March 24, 2022

Script Runner,JEP,JSU automation Suite

Suggest an answer

Log in or Sign up to answer