Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create a calculated custom field based on the values of other custom fields

Hi guys, 

I need to create a non-editable calculated custom field where the value will be based on the values from two other custom fields (single select list). From what I understand this would need to be done in Scriptrunner in my case (on Server/Data Center and don't have JMCF) however, I'm very new to it so I'm not sure how to format the script and when looking online I don't really find what I need.  

Example: 

Field A:

  • 1
  • 2
  • 3

Field B:

  • 1
  • 2

Calculation: Value in Field A + Value from Field B = Value in Field C. 

Anyone got an idea of how to do this in the best way? 

Thanks in advance, 

 

1 answer

0 votes

With scriptrunner, this assumes the most simple case:

Add a scripted field, selecting a template for it as "numeric" (note you will also need to look at the custom field definition to choose a "searcher" - probably want to use "number range" for that), and add a script like:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

final customFieldNameA = 'Field A'
final customFieldNameB = 'Field B'

def customFieldA = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldNameA }
def customFieldB = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldNameB }

return issue.getCustomFieldValue(customFieldA) + issue.getCustomFieldValue(customFieldB) 

Note that this assumes fields A and B are numeric - if they are not, you will need to convert their values to numbers.  There's also no error checking - it assumes the fields are always filled.

Hi Nic, 

Thank you for your reply! 

I tried with the above but think I'm missing something as the return give me an "unable to return class Impact" error. 

The name of Field A is Probability and Field B is Impact Value. They are both Select List (single choice) with the numbers 1,2,3 as options. Would these need to be Number Fields for this to work? 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

final customFieldNameA = 'Probability'
final customFieldNameB = 'Impact Value'

def customFieldA = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldNameA }
def customFieldB = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldNameB }

return issue.getCustomFieldValue(Probablility) + issue.getCustomFieldValue(Impact Value)

Thanks a lot for your assistance! 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

385 views 5 12
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