I would like to set a rule so that when Custom Field 1 is set to A, Custom Field 2 cannot be left blank. If it’s blank, an error should appear and the transition to the next status should be blocked.
However, the script I used isn’t working — can anyone help?
I’ve also added a validator that requires Story Points to be filled in before moving to the next status.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Get fields by ID — update these IDs to match your actual custom field IDs
def customField1 = customFieldManager.getCustomFieldObject("customfield_10001") // Custom Field 1
def customField2 = customFieldManager.getCustomFieldObject("customfield_10002") // Custom Field 2
// Get field values
def field1Value = issue.getCustomFieldValue(customField1)?.toString()
def field2Value = issue.getCustomFieldValue(customField2)
// Validation logic
if (field1Value?.equalsIgnoreCase("A")) {
if (!field2Value) {
// Show error and block transition
invalidInputException = new com.opensymphony.workflow.InvalidInputException(
"Custom Field 2 must be filled when Custom Field 1 = A."
)
throw invalidInputException
}
}
// Allow transition
return true