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,293,780
Community Members
 
Community Events
165
Community Groups

Scriptrunner, Substract values from a select list depending on the values chosen on another list

We've been given three custom fields, Batch 1, Batch 2 and Batch 3.

Each one is a multi-select list with the same list of options.

However any option selected on Batch 1 must be substracted from the selection of Batch 2, and any option chosen on Batches 1 and 2 must disappear from the options in Batch 3.

 

I have managed to make the operation with a Script Behaviour but only with Single Select Lists (which sadly is to little use when you have more than 50 values per list), Multi-select lists only remove the value 'None' in Batches 2 and 3, no matter if the values in Batch 1 change.

 

Here's the code I have, it works on single select lists but not on multi-select:

import com.atlassian.jira.component.ComponentAccessor


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def Batch1Field = getFieldByName("Batch 1")
def Batch1Val = Batch1Field.getValue()

def Batch2Field = getFieldByName("Batch 2")
def customFieldB2 = customFieldManager.getCustomFieldObject(Batch2Field.getFieldId())
def configB2 = customFieldB2.getRelevantConfig(getIssueContext())
def optionsB2 = optionsManager.getOptions(configB2)

def optionsMapB2 = optionsB2.findAll {
it.getValue() != Batch1Val
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
Batch2Field.setFieldOptions(optionsMapB2)

def Batch2Val = Batch2Field.getValue()
def Batch3Field = getFieldByName("Batch 3")
def customFieldB3 = customFieldManager.getCustomFieldObject(Batch3Field.getFieldId())
def configB3 = customFieldB3.getRelevantConfig(getIssueContext())
def optionsB3 = optionsManager.getOptions(configB3)

def optionsMapB3 = optionsB3.findAll {
it.getValue() != Batch1Val && it.getValue() != Batch2Val
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
Batch3Field.setFieldOptions(optionsMapB3)

 Got no idea on how to proceed forward, been stuck at this point looking for a way through for a couple of hours by now... I'd appreciate any ideas dropped by.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

220 views 0 6
Join discussion

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