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

Nancy Belser July 19, 2012

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

0 votes
Renjith Pillai
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.
July 20, 2012

Indeed Behaviour plugin is meant for this.

Nancy Belser August 21, 2012

I ended up using a groovy script.

MarkW October 8, 2012

Hi Nancy,

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

Nancy Belser October 21, 2012

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
TAGS
AUG Leaders

Atlassian Community Events