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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Marketplace Apps & Integrations

Learn how to request and manage app requests in the Marketplace

G’day everyone! Super exciting news coming from the Marketplace. We have now fully rolled out the ability for end-users to submit app requests to admins directly from within the product! No longer ...

43 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you