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

Behaviours on Affects Versions based on a field value

Kurt October October 16, 2020

Hi All,

I hope you could help me with this cause i am struggling to get this to work... Also, I am not too clued up on Groovy Scripting so I am going based on researched, etc.

On JIRA Service Desk we have three fields we would like to limit based on a choice made in a dropdown. So the setup we have is something similar to below:

Custom Field Name: Car Brand (This is a single select list field)
AffectsVersion/s (this is the project system field)
Components (this is the project system field)

So, what im after is if the Car Name is set to Ford as an example, then the Affects Versions should only show a list [Fiesta, Figo... etc]. And the same applies to the components: Select Ford and the components would need to be narrowed down to a list [Engine, Gearbox.... etc]

I haver tried using behaviours and adding server side script but im so lost as what is what and how to do etc. I have the code below... but i am not sure if im on the right path

 


import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.AFFECTED_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS

def productField = getFieldById(getFieldChanged())
def selectedProduct = productField.getValue() as String
def versionManager = ComponentAccessor.getVersionManager()
def versions = versionManager.getVersions(issueContext.projectObject)
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)

if (selectedProduct == "Ford") {
getFieldById(AFFECTED_VERSIONS).setFieldOptions(["Figo","Focus"])
getFieldById(COMPONENTS).setFieldOptions(["Engine", "Gearbox"])

}

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
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.
October 16, 2020

You were very close...

The setFieldOptions needs to set the options using the correct data type.

 getFieldById(AFFECTED_VERSIONS).setFieldOptions(versions.findAll{it.name in ["Figo","Focus"]})
getFieldById(COMPONENTS).setFieldOptions(components.findAll{it.name in ["Engine", "Gearbox"]})
Kurt October October 16, 2020

Thank you so much for your quick response. I truly appreciate it... However the dropdowns are still showing all the options and not the ones specified as per above.

Below is the screenshot of the actual result:

image.pngAnd below is the configuration of the behaviour:

image.pngSome more of your assistance on this would be greatly appreciated

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.
October 17, 2020

That is expected behavior. Scriptrunner behaviours are only effective in full edit screen. They can't work for in-line edits.

To get around that, you have to disable inline edits for those fields. Then, when the user attempts inline edit, the edit screen will pop up.

To disable those inline edits, just add those 2 fields to your behaviour configuration (just like you did for Product, but you don't need to change anything else. No serverside script, no read/hide attributes)

Kurt October October 18, 2020

This works... Thank you so so so so so much!!!!

TAGS
AUG Leaders

Atlassian Community Events