Script Runner validation of parent field (JQL > Script)

Adam Jacobson
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.
December 15, 2013

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

2 votes
Answer accepted
Ubisoft
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.
December 19, 2013

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

Adam Jacobson
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.
December 19, 2013

Just perfect! Thanks so much for your help.

0 votes
Brannon Fay December 19, 2013

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