Validation statusCategory (Done) from issue in Epic

u632570
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 26, 2022

Team I am using the following code to validate with scriptRunner in Jira server version 8.20.10, that when transitioning an Epic to the "Done" status, it validates that all
issues in the epic are in a "final" status (StatusCategory == Done)
The following code works fine when I query by status eg:

it?.destinationObject?.getStatus().getName() != 'Done' && it?.destinationObject?.getStatus().getName() != 'Canceled' &&
it?.destinationObject?.getIssueType().getName() != null

but when I try to do it with statusCategory since I contain more than one final status and I would like to simplify the code, it always returns "False".
I am using this code:

it?.destinationObject?.getStatus().getStatusCategory().getName() != 'Done' &&
it?.destinationObject?.getIssueType().getName() != null

I leave you the complete script to help me understand what I'm doing wrong...

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager

def issueMgr = ComponentAccessor.getIssueManager()
//Issue issue=issueMgr.getIssueByCurrentKey("OST-83")

// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger

// Script code for easy log identification
String scriptCode = "Check all issues in Epics are Done -"

// Setup the log and leave a message to show what we're doing
Logger logger = log
logger.setLevel( Level.ERROR )
logger.debug( "$scriptCode Triggered by $issue.key" )

def passesCondition = true
if (issue.issueType.name == 'Epic')
{
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def found = issueLinkManager.getOutwardLinks(issue.id).any
{
it?.destinationObject?.getStatus().getStatusCategory().getName() != 'Done' &&
it?.destinationObject?.getIssueType().getName() != null
}
logger.debug( "$scriptCode Found = $found " )
if (found) {
logger.debug( "$scriptCode return false" )
passesCondition = false
invalidInputException = new InvalidInputException("Por favor valide que todos los issues asociados a la epica se encuentren en estado DONE")
} else {
logger.debug( "$scriptCode return true" )
passesCondition = true
}
}
// Always allow all other issue types to execute this transition
else
{
logger.debug( "$scriptCode Not Epic return true" )
passesCondition = true
}


I thank you in advance for your prompt help!
Best regards!!!

1 answer

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 26, 2022

Hi @u632570 

The value to compare with is not Done but COMPLETE I think.

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/status/category/StatusCategory.html

 

static String COMPLETE
static String IN_PROGRESS
static String TO_DO
static String UNDEFINED

Suggest an answer

Log in or Sign up to answer