Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

convertToSingleSelect behaviour

Kyrylo Filipenkov
March 2, 2018

Hello,

I use benaviour and rest endpoint to query the database.
There are two fields. One for input data. Other for output data.
I want to query the database by value from the first field and output the result into the second field. The result in the second field is a drop-down list.

But I do not know how to transfer data from the first field to the rest endpoint script to execute the query in the database 

Help me please with the solution of the problem.

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 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.

achoudhary
August 18, 2022

Hi @PD 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 

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 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
achoudhary
August 24, 2022

@PD Sheehan 

 

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

 

Regards,

Ankit

TAGS
AUG Leaders

Atlassian Community Events