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?
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)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.