When I'm executing an enhanced search with the ScriptRunner Enhanced Search interface (I'm using Atlassian Cloud) my query will execute and not provide results. The "in progress" loop will cycle endlessly beside the "0-0 of 0" string. Issues are synced. The query is syntactically correct. The query should produce results.
If I save the query (say, as "enhanced search 1"), then go to a JIRA jql search and write filter = "enhanced search 1", I will get search results-- why won't they show in the search results pane in the ScriptRunner Enhanced Search interface?
I need to close the tab or browser and start another in order to write another enhanced search query.
Hi Melanie
Welcome to the community :)
There are dozens of such examples in the community, but here is how I would do it.
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)This script should be applied to the server-side script for FieldA. This will make the script run each time fieldA is changed.
Writing it this way makes it easier to copy to other scenarios and/or add new option mapping in the future.
Hi @PD Sheehan
thanks so much for your help. Really appreciate it! 🙏
I applied it to my fieldA but I'm getting two errors, not sure if I can just ignore them or if its something that must be fixed to have it work properly..
-> def allOptions = optionsManager.getOptions(config)
variable is undeclared
-> map[formFieldA.value].contains(option.value)
no such property: value for class: java.lang.Object
Could you have a look at it and tell me, what needs to be changed/added here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah... sorry, I wasn't careful with the details.
Add the following 3 lines a tthe top of the script:
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did it. No errors now. But it's only working for my first mapping.
So selecting A shows the multi-select with the options I want but selecting B shows nothing at all, the multi-select field is not showing up.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make sure the spelling for B matches the first part in my example
def map = [
'A':['Monday', 'Wednesday'],
'AB':['Monday', 'Tuesday']
]
I took you literally and labeled the second option "AB". If your second label is B and not AB, then your map will look like this:
def map = [
'A':['Monday', 'Wednesday'],
'B':['Monday', 'Tuesday']
]
Beyond that, I'll need to see your full script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def formFieldA = getFieldByName('Zielgruppe')
def formFieldB = getFieldByName('Tätigkeit')
def map = [
'Büropersonal':["Arbeitszeitmanager/-in","Betriebsdisponent/-in","Betriebsmanager", "Fahr-, Dienst- und Umlaufplaner/-in","Koordinator Kundendialog", "Leiter Fahrgastmarketing", "Leiter/-in Niederlassung" ,"Marktmanager","Mitarbeiter Fahrtwunschzentrale", "Personaldisponent/-in","Referent Fahrgastmarketing", "Referent Kommunikation", "Sachbearbeiter Abomanagement","Sachbearbeiter Kundencenter","Sachbearbeiter Kundendialog","Teamleiter Abomanagement","Teamleiter Fahrdienst","Teamleiter Fahrtwunschzentrale","Teamleiter Kundencenter","Teamleiter Leistelle","Teamleiter Werkstatt"],
'Fahrpersonal':["Busfahrer","Teamleiter Fahrdienst"]
]
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)
Thats how it looks. The Values I gave you were just examples because, as you can see, there are a lot of values I want to show
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't see anything inherently wrong there.
You can add something like this to give you immediate clues:
formFieldA.setHelpText("Detected value $formFieldA.value (${formFieldA.value.getClass()}) in $formFieldA.fieldId this maps to ${map[formFieldA.value]}")That might provide some clues. Maybe there is a slight spelling diference.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, added this to my script and I noticed something odd while running it.
Selecting A gets me the multi-select and some info what options are mapped to A.
Selecting B only gets me the info about the mapped options, but no multi-select.
And selecting another option C in FieldA shows me the info about the mapped options even tough I haven't even mapped them. But it says, that the options from B are also mapped to C. I made some screenshots so it might be more clear.. except the lines you posted last I havent changed anything in the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, added this to my script and I noticed something odd while running it.
Selecting A gets me the multi-select and some info what options are mapped to A.
Selecting B only gets me the info about the mapped options, but no multi-select.
And selecting another option C in FieldA shows me the info about the mapped options even tough I haven't even mapped them. But it says, that the options from B are also mapped to C. I made some screenshots so it might be more clear.. except the lines you posted last I havent changed anything in the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When the helpText doesn't change after you change the single-select, I suspect there is some error happening in the code. If you have access to your <jira-home>/log/atlassian-jira.log I suspect you will find some additional clues there.
But given that you have unmapped options that I assume you want to default to showing all options in that case.
You can try this
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def formFieldA = getFieldByName('Zielgruppe')
def formFieldB = getFieldByName('Tätigkeit')
def map = [
'Büropersonal':["Arbeitszeitmanager/-in","Betriebsdisponent/-in","Betriebsmanager", "Fahr-, Dienst- und Umlaufplaner/-in","Koordinator Kundendialog", "Leiter Fahrgastmarketing", "Leiter/-in Niederlassung" ,"Marktmanager","Mitarbeiter Fahrtwunschzentrale", "Personaldisponent/-in","Referent Fahrgastmarketing", "Referent Kommunikation", "Sachbearbeiter Abomanagement","Sachbearbeiter Kundencenter","Sachbearbeiter Kundendialog","Teamleiter Abomanagement","Teamleiter Fahrdienst","Teamleiter Fahrtwunschzentrale","Teamleiter Kundencenter","Teamleiter Leistelle","Teamleiter Werkstatt"],
'Fahrpersonal':["Busfahrer","Teamleiter Fahrdienst"]
]
def cfFieldB = customFieldManager.getCustomFieldObject(formFieldB.fieldId)
def config = cfFieldB.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(config)
def optionsToAllow
def selected = formFieldA.value
if(selected in map.keySet()){
formFieldA.setHelpText("Detected mapped value $formFieldA.value in ${formFieldA.fieldId}. Multi-select will be limited to ${map[formFieldA.value]}")
optionsToAllow = allOptions.findAll{ option->
map[formFieldA.value].contains(option.value)
}
} else {
formFieldA.setHelpText("Detected unmapped value $formFieldA.value in ${formFieldA.fieldId}. Multi-select will include all options")
optionsToAllow = allOptions
}
formFieldB.setFieldOptions(optionsToAllow)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was able to find the reason why it wasn't working. Another plugin was the reason. Now everything works perfectly :) Thank you so much for you help and patience!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Happy to help.
Glad you figured it out. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.