Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,556,072
Community Members
 
Community Events
184
Community Groups

Need scripted custom fields= to calculate sum up based on other field values

I need Scripted field will sum up the score values and show it in the ticket on.

For example, I have 3 fields called

  1. Sensitive = Values are Yes, No, Others (Score Values Yes=5, No=0)
  2. Automated = Values Yes, No (Score Values Yes=10, No=5)
  3. Region = Values are USA, UK, Africa, Chinna, Brazil (Score Values USA=8, UK=7, Africa=5, Chinna=6, Brazil=7)

I need a script field that calculate values numbers.

ex Sensitive=Yes, Automated=No, Region=USA Total values 5+5+8 = 10 should be on scripted field.

 

 

 

1 answer

1 accepted

0 votes
Answer accepted

import com.atlassian.jira.component.ComponentAccessor

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()

def a = CustomFieldManager.getCustomFieldObject(xxxxx)

def b = CustomFieldManager.getCustomFieldObject(xxxxx)

def c = CustomFieldManager.getCustomFieldObject(xxxxx)

def aValue =  issue.getCustomFieldValue(a)

def bValue =  issue.getCustomFieldValue(b)

def cValue =  issue.getCustomFieldValue(c)

int aDigit

int bDigit

int cDigit

switch(aValue){

    case "Yes":

    aDigit=5

    break

    case "No":

    aDigit=3

    break

    default:

    aDigit=0

   

}

switch(bValue){

    case "Yes":

    bDigit=10

    break

    case "No":

    bDigit=5

    break

    default:

    bDigit=0

   

}

switch(cValue){

    case "UK":

    cDigit=8

    break

    case "Africa":

    cDigit=7

    break

    default:

    cDigit=0

   

}

int sum = aDigit + bDigit + cDigit

return sum


Hi @Arkadiusz Baka , Thanks for your reply and code,

It worked for single list field but for multi select field it is not working, I have modified the code to get multi select field value but no luck,  

Can you help me that same?

Thanks

Multi select field is a list. Try something like that:

HashMap<String, Integer> country = new HashMap<String, Integer>();

// Add keys and values (country , value)
country.put("USA", 8);
country.put("UK", 7);
country.put("Africa", 5);
int count=0;

for (String key:list) {
if (country.containsKey(key)){
count+=country.get(key);
}
}

Where list is getting form multi select field

Hi @Arkadiusz Baka , 

For my case "Sensitive" and "Automated" is single list and Country is multi select field.

Help me the same.

Something like that

import com.atlassian.jira.component.ComponentAccessor

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()

def a = CustomFieldManager.getCustomFieldObject(xxxxx)

def b = CustomFieldManager.getCustomFieldObject(xxxxx)

def c = CustomFieldManager.getCustomFieldObject(xxxxx)

def aValue =  issue.getCustomFieldValue(a)

def bValue =  issue.getCustomFieldValue(b)

def cValue =  issue.getCustomFieldValue(c)

int aDigit = 0

int bDigit = 0

int cCount = 0

switch(aValue){

    case "Yes":

    aDigit=5

    break

    case "No":

    aDigit=3

    break

    default:

    aDigit=0

   

}

switch(bValue){

    case "Yes":

    bDigit=10

    break

    case "No":

    bDigit=5

    break

    default:

    bDigit=0

   

}

HashMap<String, Integer> country = new HashMap<String, Integer>();

// Add keys and values (country , value)

country.put("USA", 8);

country.put("UK", 7);

country.put("Africa", 5);

for (String key:cValue) {

if (country.containsKey(key)){

cCount+=country.get(key);

}

}

int sum = aDigit + bDigit + cCount

return sum

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events