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

gil June 27, 2014

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

1 vote
Vijay Khacharia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2014

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

gil June 29, 2014

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.

Vijay Khacharia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2014

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)

roniz January 1, 2018

@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?

0 votes
Maya_Chase August 31, 2017

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?

Maya_Chase August 31, 2017

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

0 votes
Marcus Silveira
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 27, 2014

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

Suggest an answer

Log in or Sign up to answer