Using script runner in workflow validator (issueFunction in linkedIssuesOf)

We have used script runner functions in issue filters successfully but have not been able to use them in workflow validators.

The objective is to prevent the closure of an issue if it has linked issues that are still open. For example issueFunction in linkedIssuesOf("status = open"). The validator returns a workflow exception indicating No such property: issueFunction.  I suspect this may be due to missing import statements or just bad syntax but have not been able to find any examples of using the script runner issueFunction in a validator. 

 

2 answers

Hi Robert,

Try using the script below in a Custom script validator

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.opensymphony.workflow.WorkflowContext

Issue issue = issue
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

String currentUserName = ((WorkflowContext) transientVars.get("context")).getCaller()
def currentUser = ComponentAccessor.getUserManager().getUserByKey(currentUserName)
def flag = issueLinkManager.getLinkCollection(issue, currentUser)?.allIssues?.find {it.status.statusCategory.name != "Complete"}

if (flag)
    throw new InvalidInputException("At least one linked issue is still open or in progress")

You may need to replace 'Complete' with the status category name that you have configured for closed issues.

Tested with a JIRA7 instance. Please let me know if this does the trick

regards, Thanos 

I cut pasted the script exactly as shown and received the following error message.  

An unknown exception occured executing Validator com.atlassian.jira.workflow.SkippableValidator@28db70f8: root cause: Cannot cast object 'com.innovalog.jmwe.IssueProxy@45c36f70' with class 'com.innovalog.jmwe.IssueProxy' to class 'com.atlassian.jira.issue.Issue'

It seems that you have tried to perform an illegal workflow operation.

If you think this message is wrong, please contact your JIRA administrators.

Hi Robert

Sorry for the misunderstanding, I though you were using ScriptRunner (even though I believe that the issueFunction in linkedIssuesOf("status = open") is a ScriptRunner scripted JQL function)

 

You must have ScriptRunner Robert so you should just be able to replace the validator with the one provided by Thanos, rather than using whatever function JMWE is providing.

We have the JIRA add-on titled "Adaptavist ScriptRunner for JIRA" installed and have successfully used the ScriptRunner function "issueFunction in linkedIssuesOf" in issue filters.  We have the evaluation version of the ScriptRunner installed as shown in the add-on maintenance information below, so perhaps that is the problem. We were hoping to verify functionality prior to recommending the purchase of a 2000 user license.

Is a different version of ScriptRunner or another component or tool that is required?

Version: 4.3.13

Vendor: Adaptavist.com Ltd

Add-on key: com.onresolve.jira.groovy.groovyrunner

License details: Evaluation, Unlimited-user commercial license, Standard, expires 12/Jan/17

License status: Valid

License SEN: SEN-L8985939

 

Check https://answers.atlassian.com/questions/134531 of how to use JQL in groovy script

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,717 views 17 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