Hi all!
I've written two very similar scripts for adding values to an attribute in Jira Assets.
First one works as expected - add all values (multiple) to the attribute:
def app_1, org_1, app_2, org_2
Assets.search('objectType = Items AND Application IS NOT empty AND Organisation IS NOT empty').each { item ->
app_1 = item.getAttributeValues('Application')[0].value
org_1 = item.getAttributeValues('Organisation')[0].value
Assets.search('objectType = Budgets').each { budget ->
app_2 = budget.getAttributeValues('Application')[0].value
org_2 = budget.getAttributeValues('Organisation')[0].value
if (app_2 == app_1 && org_2 == org_1) {
budget.update {
setAttribute('Items') {
add(item)
}
}
}
}
}
On the other hand, the second one adds one value only and if there are multiple values, the previous one is replaced by the new one: def items = []
def budgets = []
Assets.search('objectType = Items AND Application IS NOT empty AND Organisation IS NOT empty').each { item ->
items.add(item)
}
Assets.search('objectType = Budgets').each { budget ->
budgets.add(budget)
}
budgets.each { budget ->
items.each { item ->
if (budget.getAttributeValues('Application')[0].value == items.getAttributeValues('Application')[0].value &&
budget.getAttributeValues('Organisation')[0].value == items.getAttributeValues('Organisation')[0].value) {
// Not working as exptected with multiple objects - newly added attribute replaces the previous one
budget.update {
setAttribute('Items') {
add(item)
}
}
}
}
}
Does anybody have an idea what is going on in the background?