Please advise how to change the script to make it work. This script is used in the post function, the latest in the queue.
At the moment, the issues from Epic have the type DocumentIssueImpl. Because of this, the status of the last issue, which goes to the status Closed is always displayed as the previous. That is, issue.statusId shows the status that the issue has moved, and the line search.results.every{it.statusId == "6"} shows that the current issue is still in the previous status.
How to make this selection readable?
The script was edited to the correct version:
com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
// Stop the script if the issue is Epic
if (issue.issueTypeId ==<span> </span>"6") {
return
}
// ID of "Epic link" field and current user
Long EPICLINK =<span> </span>14500
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get managers
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customfieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def workflowManager = ComponentAccessor.getWorkflowManager()
def issueService = ComponentAccessor.getIssueService()
// Epic of the current issue
def epicLinkCustomField = customfieldManager.getCustomFieldObject(EPICLINK)
String epicLink = issue.getCustomFieldValue(epicLinkCustomField)
def currentEpic = ComponentAccessor.getIssueManager().getIssueByCurrentKey(epicLink)
// Stop the script If the issue has no Epic
if (!currentEpic) {
return
}
// JQL to retrieve all issues in the Epic
def query = jqlQueryParser.parseQuery("issueFunction in issuesInEpics(\"key = ${currentEpic.key}\")")
def search = searchService.search(currentUser, query, PagerFilter.getUnlimitedFilter())
def searchResults = search.getResults().findAll{ it.getKey() != issue.getKey() }<span> </span>// Excluding the current issue, which goes to status "Closed"
// Epic's workflow
def workflow = workflowManager.getWorkflow(currentEpic)
int actionID =<span> </span>21 // Resolved status
def transitionValidationResult = issueService.validateTransition(currentUser, currentEpic.id, actionID,<span> </span>new IssueInputParametersImpl())
// Transition the epic to Resolved status only if all issues in the epic are closed
if (searchResults.every{it.getStatusId() ==<span> </span>"6"}) {
String newComment =<span> </span>"The issue is resolved. Please check all the updates and manually close it."
issueService.transition(currentUser, transitionValidationResult)
ComponentAccessor.getCommentManager().create(currentEpic, currentUser, newComment, false)
}import
Please specify if there are errors or lines in my code that can be improved. I'd be grateful. (apologies if there are typos)
P.S.
The script is written in a readable form to make it easier for my colleagues to read it. They don't write scripts.