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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 10, 2018 in Marketplace Apps

Learn about how Stefan K. built one of the *first ever* Marketplace apps

In this post you will discover more about the evolution of K15t software, some big topics they're currently focusing on in the app space, and a rare (not not funny!) photo of founders Mike Cannon-Bro...

12,843 views 11 24
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