Making a JIRA field required based on a value chosen on the screen and it's not yet stored in the database

I need some help for the following configuration in JIRA:

On workflow transition screen, if the user selects "Implemented" on the Resolution dropdown on the screen, I would want a custom dropdown field a required one. Similarly, I also want the Fix Version field must have at least 1 Fix Version.

I don't think Behaviour plugin does what I need here because of the 'Resolution' condition here. Maybe I miss something?

If I am to script this, I can read the stored value, but in this case, the value chosen in the Resolution, custom dropdown field and the Fix Version are not saved to the database. How do I get the chosen value on the screen which is not yet saved to database?

Thanks.

3 answers

This widget could not be displayed.

Hi,

You can add a validator and check the value of Resolution. This will be the resolution on the screen. If resolution is "Implemented" you can then check for the FixVersion field.

You can do this using Script runner plugin if you are not using OnDemand JIRA.

import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Category
 
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
 
Issue myIssue = issue
 
if (myIssue.getResolutionObject().getName() == "Implemented" && ! myIssue.getFixVersions().size()) {
    invalidInputException = new InvalidInputException("fixVersions", "Fix Version/s is required when specifying Resolution of \"Implemented\"")
}

Here is the code from the plugin documentation.

Vijay

That works perfectly, Vijay. On a site question, how do I get a value on a custom dropdown? Please keep in mind that the value on this dropdown is not yet saved to the database yet, and thus I need the chosen value on the screen. Thanks.

The validator has access to all the values selected/filled on the screen/transition which this validator is for. So you can get access to the customfield value as you get it for resolution. Below is pseudo code.

customFieldManager = ComponentAccessor.getCustomFieldManager()
cf1= ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field Name")

CustomFieldValue = issue.getCustomFieldValue(cf1)

@Vijay Khacharia,

I am trying to create a validator that only if a certain custom field by the name X equals (from a drop down list) "abc", then the user needs to attach an attachment by the name "xyz" in order to move to the finishing status of the ticket.

 

I tried to write a code for this- whiteout any success. can you help me please?

This widget could not be displayed.

Hi Gil,

Maybe you can try using some javascript customization directly to your field's description to fulfil those requirements.

Here are some links that might help with this.

Fields Allowing Custom HTML or JavaScript

Displaying a Field Based on Another Field Selection

Hope this helps

This widget could not be displayed.

I put this validator in my workflow:

import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")

Issue myIssue = issue

if (myIssue.getResolution().getName() == "Fixed" && myIssue.getFixVersions().size()) {
invalidInputException = new InvalidInputException("fixVersions", "Fix Version/s is required when specifying Resolution of \"Fixed\"")
}

It works with no errors, except that when the resolution is Fixed it does not thow the exception or give a message or anything, it just transitions the issue. Why? And how do I fix it?

Never mind, I figured it out. Left out the "!" in the boolean expression.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

189 views 3 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you