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,365,234
Community Members
 
Community Events
168
Community Groups

Behaviour on Multiselect

def formFieldA = getFieldByName('fieldA')
def formFieldB = getFieldByName('fieldB')
def map = [
'A':['Monday', 'Wednesday'],
'AB':['Monday', 'Tuesday']
]

def cfFieldB = customFieldManager.getCustomFieldObject(formFieldB.fieldId)
def config = cfFieldB.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(config)

def optionsToAllow = allOptions.findAll{ option->
map[formFieldA.value].contains(option.value)
}
formFieldB.setFieldOptions(optionsToAllow)

I have this script which is working fine.. select list changing multi slect.

What i should change here to have multiselect change multi slect?

 

Please let me know 

1 answer

1 accepted

1 vote
Answer accepted

Have you put some thought into how you want the source multi-select to influence the target multiselect?

What happens when multiple items are selected? Does the target multi-select simply offer a combination of choices mapped to each source option?

If so, this should roughly work:

def formFieldA = getFieldByName('fieldA')
def formFieldB = getFieldByName('fieldB')
def map = [
'A':['Monday', 'Wednesday'],
'AB':['Monday', 'Tuesday']
]

def cfFieldB = customFieldManager.getCustomFieldObject(formFieldB.fieldId)
def config = cfFieldB.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(config)

def optionsToAllow = allOptions.findAll{ option->
(formFieldA.value as List).any{map[it].contains(option.value)}
}
formFieldB.setFieldOptions(optionsToAllow)

 Othe types of interactions/algorithm will require more specific example.

Hi @Peter-Dave Sheehan :

Thanks a lot for the solution. It worked fine. I was also doing it as a test case before i go for actual requirement If you can help in my actual requirement it would be very helpful to me.

I have two fields 

Affected version for clients - (Multiversion picker) 2.3, 2.4,2.5 

Other affected Clients - (Multiselect field) A, B, C, D

2.3 is related to A & B

2.4 is related to C

If i select 2.3, 2.4 is version, the Other affected Clients should automatically map to A, B, C.

I wrote this code from your solution provided. But its not taking the values. Can you please help

 

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def versionManager = ComponentAccessor.getVersionManager()

def optionsManager = ComponentAccessor.getOptionsManager()

def formFieldA = getFieldById(fieldChanged)
def formfieldAValue = versionManager.getVersion(issueContext.projectObject.id).getId() as List
def formFieldB = getFieldByName('Other affected clients')
def map = ['2.3':['A','B'],'2.4':['C'],'2.5':['D']]

def cfFieldB = customFieldManager.getCustomFieldObject(formFieldB.fieldId)
def config = cfFieldB.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(config)

def optionsToAllow = allOptions.findAll{ option->
(formfieldAValue).any{map[it].toString().contains(option.value)}
}

formFieldB.setFormValue(optionsToAllow*.OptionId)
log.warn("test"+optionsToAllow)

Regards,

Ankit 

So, it looks like you are getting a formfield object: formFieldA, and then you don't use that anywhere.

How did you think you were getting the selected values?

You can add a line of code like this to give you some clues as to what happens when you select a version:

formFieldA.setHelpText("$formFieldA.value (${formFieldA.value[0].getClass()})")

What I saw in my environment was "VersionImpl".

So I renamed some variables and adjusted the code to take that into consideration

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.VersionImpl

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def versionManager = ComponentAccessor.getVersionManager()

def optionsManager = ComponentAccessor.getOptionsManager()

def formFieldA = getFieldById(fieldChanged)
def selectedVersions = formFieldA.value as List<VersionImpl>
def formFieldB = getFieldByName('Other affected clients')
def map = [
'2.3': ['A', 'B'],
'2.4': ['C'],
'2.5': ['D']
]

def cfFieldB = customFieldManager.getCustomFieldObject(formFieldB.fieldId)
def config = cfFieldB.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(config)

def optionsToSet = allOptions.findAll { option ->
(selectedVersions).any { selectedVersion -> map[selectedVersion.name].contains(option.value) }
}

formFieldB.setFormValue(optionsToSet*.optionId)
log.warn("test" + optionsToSet)

 

Like achoudhary likes this

@Peter-Dave Sheehan 

 

Thanks a lot, it solved all issue and things you pointed out really helps me in future.

 

Regards,

Ankit

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events