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

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

Desarrollo_3digits September 7, 2018

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
AUG Leaders

Atlassian Community Events