You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
For example, I have 3 fields called
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Arkadiusz Baka ,
For my case "Sensitive" and "Automated" is single list and Country is multi select field.
Help me the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.