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.