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

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


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


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!


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
Community Members
Community Events
Community Groups

Require Component/s field based on a value selected from a custom field

I need helping creating a validator script (I think) to make the Component/s field required based what the user selects from a single select custom field.

Use Case:

1. Single select drop-down field called "Atlassian Platform" with two value options: Confluence, Jira. 

2. If user selects "Jira" from the "Atlassian Platform" field then the Component/s field is required (nothing happens if user selects "Confluence")

2 answers

0 votes

It is possible to achieve this with either a Behaviour or a validator.

Behaviour scripts are capable of knowing which part of the workflow you are in. This is a good choice if you want to prevent users from clearing the component using the edit screen after it's deemed required.

Of course, a validator will work inherently within the workflow but will allow users to edit the component after the transition has taken place.

A Simple Scripted validator would look like this:

cf["Atlassian Platform"].value != 'Jira' || issue.components

Simple Scripted validators must return a true value to pass or false to generate an error.


A behaviour script would be a little more complicated:

if(!underlyingIssue) return //don't run the validator on create screen when the underlyingissue does not yet exist

def transitionToMakeCompoenntRequired = 'name of transition'
def statusesAfterThatTransition = ['status1', 'status2']
def componentsField = getFieldById('components')
def platformField = getFieldByName('Atlassian Platform')

def isTargetAction = actionName == transitionToMakeCompoenntRequired 
def isTargetStatus = in statusesAfterThatTransition
def isRequiredValue = platformField.value == 'Jira'

def componentRequired = (isTargetAction || isTargetStatus) && isRequiredValue

@Peter-Dave Sheehan Unfortunately the simple scripted validator didn't work.  I also ended up having to change my custom field name from Atlassian Platform to AM Application. 


Sorry... I was sloppy. It should be "cfValues", the built-in variable that scriptrunner offers that includes all the custom field values in an easily accessible map.

cfValues["AM Application"].value != "JIRA" || issue.coponents

Bummer, still not working. I tried with both single quotes and double quotes.

cfValues['AM Application'].value != 'JIRA' || issue.coponents 

I was clearly under-caffeinated yesterday ... there was another typo: coponents vs components

cfValues["AM Application"].value != "JIRA" || issue.components

Oops, I meant to say that caught the misspell but it's not working. 

Can you share some more details? Are there any errors in the script editor?

Do you see errors in the execution log (open the workflow/transition after executing the transition to view execution logs).

Maybe we can add some additional logging to help with identifying where it's failing: "'AM Application' is ${cfValues["AM Application"].value}" "issue.compoenents is $issue.components" "am application check is:${cfValues["AM Application"].value != "JIRA"}" "issue.component check is ${issue.components ? true : false}" "final validation result is ${cfValues["AM Application"].value != "JIRA" || issue.components}"

cfValues["AM Application"].value != "JIRA" || issue.components

Here's a screenshot of the results and logs.  Also, shouldn't it be == "JIRA" instead != "JIRA" because I only want Component/s field to be required if JIRA is selected. 


Script Console_1.PNGScript Console_2.PNG

The script will not work in the Script Console.

In a simple scripted validator script editor window, there will be some built-in variables and objects (you can see which by clicking the question mark below the editor).

issue and cfValues is two of those variables.

These variable are not available in the console since it's not aware of what ticket you want to act on etc.

As for the logic for the selected value... you want to return a "true" value (i.e. allow the transition to continue) either when the AM Application is something OTHER than Jira, OR if they've selected JIRA, then the components must be specified.

The way an OR (||) is processed, is that it will return true at the first instance that is true.

So from left to right, the first statement evaluated will be "AM Application" different than JIRA. If true, then return true and allow the transition. If False (AM Application IS JIRA) then evaluate the next statement. 
Groovy has "thrutiness" shortcuts. So here, we are essentially validating that issue.components.size() > 0.

So, the final rule is, when AM Application is JIRA at least one component must be present.

0 votes

Hi @John Diaz 

Using ScriptRunner Behaviours will let you do that easily. Take a look at this script.


@Ravi Sagar _Sparxsys_  I appreciate the quick response.  Unfortunately, Behavior isn't going to work for me.  

There's a certain part of the workflow where I want someone on my team to be forced to enter a Component when moving the ticket "In Progress" ONLY IF "Jira" is selected from the "Atlassian Platform" field.  So Component isn't required at the start of the ticket creation and will not be required if "Confluence" is selected. 

Apologies for not providing enough context with what I'm trying to accomplish. 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events