Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

[ScriptRunner] Validation issues in Epic are close

valeria cruz June 30, 2021

Hello guys!

I'm trying to create a wf validation to verify all the issues in Epic are closed, using scriptrunner validation.

 

This is my script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor

MutableIssue epicLink = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Epic Link")) as MutableIssue;
IssueLinkManager issueLinkManager = ComponentManager.getInstance().getIssueLinkManager();

def Issue = getIssuesInEpic(epicLink)

if ({
!issue.get("Epic Link") || issue.get("Epic Link").getAsString("status") in ["Done","Cancel"]
})

return true

else return false

 

But, for some reason, isn't work T_T

Someone can help me?

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2021

There are several issues with this script (or you didn't give us all of it)... it might be easier to start over.

What's the trigger here? Are we talking about the workflow transition on the Epic itself? Or transition on all the issues in the epic?

If it's the transition in the epic (e.g. prevent closing the epic if the issue in the epic are open), you'll be better off use the "epicLinkManager"

Something like this:

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.pyxis.greenhopper.jira")
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
@JiraAgileBean
EpicLinkManager epicLinkManager
//issue should be the epic issue that called the validator
epicLinkManager.getIssuesInEpic(issue).any{!(it.status.name in ['Done', 'Cancel'])}

 

If the trigger is one of the issues in the epic, then you must first find the epic issue.

Your script had some elements of that, but I think the epicLinkManager is more succinct:

def epic = epicLinkManager.getEpic(issue).get()
def issuesInEpic = epicLinkManager.getIssuesInEpic(epic)

Compared to:

def epicLinkCf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Epic Link")
def epic = issue.getCustomFieldValue(epicLinkCf)
def issuesInEpic = epicLinkManager.getIssuesInEpic(epic)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events