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)?

Thanks!

2 answers

1 accepted

This widget could not be displayed.

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()
log.warn(parentCustomFieldValue)
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.

This widget could not be displayed.

Adam,

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.

Cheers,

Brannon

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

207 views 1 3
Join discussion

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