How do I make a field required based upon the value of another field set in workflow transition screen?

I have a transition screen that will display customfield2 for edit based upon the value of customfield1 (set on same transition screen). I am using java script in the description to do this.

I would also like to make customfield2 required if customfield1 is set to a certain value. I have tried doing this via a simple validation using groovy runner. This works in test mode, but in groovy runner test mode, the values have already been set and stored in the database. When I try it as a workflow validator, this does not work. I suspect that because the values have not been stored yet, the condition does not validate in the same way. Here is the logic:

cfValues['customfield1'].getValue() != 'Duplicate' && !cfValues['customfield2']

I need to validate the values that have been set on the screen before they are saved. How would I go about doing that (in groovy runner or another plugin, behaviors perhaps)?

1 answer

Indeed Behaviour plugin is meant for this.

I ended up using a groovy script.

Hi Nancy,

Would you be able to share what you have written with the groovy script?

The fields edits were only allowed to be made via a workflow transition, so I used the following groovy script as a validator:

import com.opensymphony.workflow.InvalidInputException

import org.apache.log4j.Category

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.MutableIssue

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

log.debug("In Validator groovy script")

MutableIssue issue = issue

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

String cfRejectReasonId = "customfield_10122"

String cfRejectDetailsId = "customfield_12030"

CustomField cfRejectReason = customFieldManager.getCustomFieldObject(cfRejectReasonId)

CustomField cfRejectDetails = customFieldManager.getCustomFieldObject(cfRejectDetailsId)

cfVal1 = issue.getCustomFieldValue(cfRejectReason).toString()

cfVal2 = issue.getCustomFieldValue(cfRejectDetails)

if ((cfVal1.compareTo("Duplicate") != 0) && cfVal2 == null) {

invalidInputException = new InvalidInputException("Customer Facing Reject Details is required when the Reject Reason is set to " + cfVal1)


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

478 views 8 28
Read article

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