Hello,
I am trying to auto close an issue (portfolio parent issue) when ALL the child issues (which are connected through parent link field) are closed/done.
For assumption :
Assume PR-1 (initiative) is parent issue which has 3 children PR-2, PR-3, PR-4. I am trying to auto close PR-1 when each of the children is moved to the Done state. Here is the script I am using :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.search.SearchProvider
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def parentLink = customFieldManager.getCustomFieldObjectByName('Parent Link') // getting the Parent Link custom field
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def customFieldValue = issue.getCustomFieldValue(parentLink) // Parent Link field value
def parentKey = (String) customFieldValue
def parentIssue = issueManager.getIssueObject(parentKey) // Parent issue object
def jqlSearch = "issuekey in childIssuesOf("+ parentIssue.getKey() + ")" ;
log.warn('JQL: ' + jqlSearch);
def query = jqlQueryParser.parseQuery(jqlSearch)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
results.getIssues().each {documentIssue ->
def issue1 = issueManager.getIssueObject(documentIssue.id)
if (issue1.getStatus().name == "Done")
{
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
}
// Validate transitioning the parent issue to "Done"
def validationResult = issueService.validateTransition(user, parentIssue.id, 41, issueInputParameters)
if (validationResult.isValid()) {
log.debug("Validation Result is valid")
// Perform the transition
def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {
log.debug("Failed to transition task ${parentIssue.key}, errors: ${issueResult.errorCollection}")
}
}
}
}
This script is working or moving the parent (PR-1) to Done even if one child is marked as Done. It is NOT iterating or waiting for the 3 children. Could anyone let me know what is the issue here?
Thanks,
Swathi