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,463,730
Community Members
 
Community Events
176
Community Groups

Behaviours on Affects Versions based on a field value

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

1 vote
Answer accepted

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"]})

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

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)

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events