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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,556,658
Community Members
 
Community Events
184
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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 16, 2022

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 

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 21, 2022

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

Atlassian Community Events