Hi, I need some help for the following issue, after trying several ways found on the web without any success.
The first step, that our users have to do, is to choose a component.
As soon as they choose "componentA", we'd like to have 2 options of a select list ("listA") filled automatically with the options "option1" and "option3".
Could you please provide me with a script for that requirement?
Thanks in advance,
Robert
I can't write this for you at the moment... there are multiple examples at https://scriptrunner.adaptavist.com/3.1.5-SNAPSHOT/jira/behaviours-overview.html and https://scriptrunner.adaptavist.com/3.1.5-SNAPSHOT/jira/recipes/behaviours.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so far, Jamie. I didn't know the new example page. I managed to prefil checkbox and list fields. But unfortunately I didn't find any example, which shows how to make a component condition like described above. I need to set the field information automatically, only IF a special component is selected. How would a component condition like this have to look like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does anybody have an idea what a component condition in a beaviour would have to look like? @Jamie Echlin [Adaptavist]?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still didn't figure out a solution. Any more help here, @Jamie Echlin [Adaptavist]?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The closest I have to your original question is here: https://gist.github.com/jechlin/8a0f026ac62091b553be - it's a bit old though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
I understand that my last couldn't work. I now define the optionToSelect like described here: https://scriptrunner.adaptavist.com/3.1.5-SNAPSHOT/jira/recipes/behaviours/setting-default-fields.html
But still nothing happens selecting the component "Frontend". But can't find a mistake either. Do you?
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.component.ComponentAccessor FormField formComponent = getFieldById(fieldChanged) def componentManager = ComponentManager.instance def optionsManager = ComponentAccessor.getOptionsManager() def spec = getFieldByName("Specifications") def customFieldManager = ComponentAccessor.getCustomFieldManager() customField = customFieldManager.getCustomFieldObject(spec.getFieldId()) config = customField.getRelevantConfig(getIssueContext()) options = optionsManager.getOptions(config) def optionsToSelect = options.findAll {it.value in ["Mechanics"]} Object componentFormValue = formComponent.getFormValue() List componentIds = [] if (componentFormValue instanceof List) { componentIds.addAll(componentFormValue as List) } else { // could be an empty string if all components are deselected if (componentFormValue) { componentIds.add(componentFormValue) } } componentIds.each { componentId -> try { Long.parseLong(componentId as String) } catch (NumberFormatException e) { log.error("Could not get component Id as Long") return } def component = getProjectComponent(Long.parseLong(componentId as String)) log.debug "name: \"" + component?.name + "\"" switch (component?.name) { case "Frontend": issue.setFormValue(spec, optionsToSelect) break } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so far.
I tried this script now for the field "component/s", but nothing happens at all when selecting "Frontend" ("Specification" is a checkbox field and "Mechanics" a valid checkbox option).
Did I get something wrong? Or is it just not possible?
FormField formComponent = getFieldById(fieldChanged) def customFieldManager = ComponentAccessor.getCustomFieldManager() def spec = customFieldManager.getCustomFieldObjectByName("Specification") Object componentFormValue = formComponent.getFormValue() List componentIds = [] if (componentFormValue instanceof List) { componentIds.addAll(componentFormValue as List) } else { // could be an empty string if all components are deselected if (componentFormValue) { componentIds.add(componentFormValue) } } componentIds.each { componentId -> try { Long.parseLong(componentId as String) } catch (NumberFormatException e) { log.error("Could not get component Id as Long") return } def component = getProjectComponent(Long.parseLong(componentId as String)) log.debug "name: \"" + component?.name + "\"" switch (component?.name) { case "Frontend": issue.setCustomFieldValue(spec, "Mechanics") break } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to set it to the ID of the option rather than the string "Mechanics". Can you try that, you can get the option ID from the page where you configure the options for the custom field. If that works I'll show you a better way where you can get the option ID from the name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mike,
we are actually improving the usability of our JIRA instance. In this case, there is one kind of bug issues (issue type "Bug" with the component "componentA") where there is some basic information, which is valid for nearly every issue. For example, we have a multi user picker field, where always the same persons have to be entered. Another field is the described "listA", where in every issue the options "option1" and "option2" should be preselected.
But as I said - only for the issue type "Bug" with the component "componentA".
The Behaviour add-on seems to be perfectly well suited for our use case. But unfortunately I couldn't figure out, what the groovy script should look like.
Regards, Robert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This does not look like the right thing to do with Jira. What is the problem you are trying to solve? Maybe we can suggest alternatives if you describe the use cases.
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.