Script Runner validation of parent field (JQL > Script)

Hi, I am trying to create a transition validator that allows a transition only if there is a non-blank field in the parent issue.

From my testing this doesn't seem achievable using the standard JIRA validators, so I'm looking at Script Runner to achieve this.

I can certainly get it going with a Condition on the workflow based on a JQL query:

issuetype = Development AND status = Testing AND issueFunction in subtasksOf ("'Release Note' IS NOT EMPTY AND issuetype in (Feature,Bug)")

The problem with this is that is removes the transition button, whereas I would prefer to display an error. JQL is not available in Script Runner validators, so I'd appeciate any pointers on

  1. whether I can actually convert this to a Simple Script validator?
  2. whether anybody can point me to a resource that shows scripting equivalents for the JQL above (not being a programmer)?


2 answers

1 accepted

1 vote
Accepted answer

HI Adam,

Here is a complete solution for you. We have this running for a few of our workflows.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException

String customFieldName = "custom field name"
String errorToShow = "No You can't"

boolean result = false;
MutableIssue muIssue = issue;
MutableIssue parentIssue = muIssue.getParentObject() as MutableIssue
CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager()
CustomField cf = cfManager.getCustomFieldObjectByName(customFieldName)
parentCustomFieldValue = parentIssue.getCustomFieldValue(cf).toString()
if (parentCustomFieldValue != "" && parentCustomFieldValue != "null")
   result = true
if (!result)
    invalidInputException = new InvalidInputException(errorToShow)

You can save this into any .groovy file

Then in your workflow validator add a script and put the path where you put the file with the filename.

edit the 2 line right after the imports to show your error and the custom field name you want to look at.

It currently set to look if it's empty.

and voilà

have fun

Just perfect! Thanks so much for your help.


Another method is with the Fields Required validator. This comes with the JIRA Suite Utilities add-on. It lets you pick multiple fields, including all custom fields in your JIRA instance.

Here is the error presented when trying to transition past this validation. You can see below Assignee is a core JIRA field but "RS - Capital Labor" is a custom field in my instance.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,772 views 18 21
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