Using script runner in workflow validator (issueFunction in linkedIssuesOf)

Robert Barnes December 15, 2016

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

1 vote
Thanos Batagiannis _Adaptavist_
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, 2016

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 

Robert Barnes December 15, 2016

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.

Thanos Batagiannis _Adaptavist_
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, 2016

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)

 

JamieA
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, 2016

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.

Robert Barnes January 3, 2017

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

 

0 votes
Alex Suslin
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, 2016

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