Hi All,
I have written a custom post function (Groovy script) to auto-transition an Epic when all the child issues are resolved. I have added that in the right place in the workflow. But, the problem is in my script, I am checking all the child issues are closed through JQL. So, My script has to wait util the indexing gets complete.
Can anyone please help me how to make my script to wait until the indexing get complete or Is there any other better solution to achieve my requirement?? Please help.
Here is my code,
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.comments.CommentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.util.ImportUtils;
if(issue.getIssueType().getName().toString() != 'Epic') {
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
IssueService issueService = ComponentAccessor.getComponent(IssueService);
CustomField epicLinkField = customFieldManager.getCustomFieldObjectByName('Epic Link');
CustomField enable_auto_transition_parent_issue = customFieldManager.getCustomFieldObject('customfield_17701');
//lookup the corresponding epic via the subtask's parent
MutableIssue epic = issueManager.getIssueObject(
(String)issue.getCustomFieldValue(epicLinkField)
);
if(epic != null) {
//Get JQL query parser and search provider object
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
// Get user object of a user to transition an epic
def userManager = ComponentAccessor.getUserManager() as UserManager;
ApplicationUser user = userManager.getUserByKey('svcjir_atadmin');
def queryString = "issue in childIssuesOf(${epic.key}) AND resolutiondate is EMPTY";
def query = jqlQueryParser.parseQuery(queryString);
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter());
def no_of_opened_child_issues = results.getIssues().size();
log.error("${results.getIssues().size()}")
log.error("${results.getIssues()[0].key}")
log.error("${results.getIssues()[0].status.name}")
if(issue.getCustomFieldValue(enable_auto_transition_parent_issue).toString() == 'ENABLED' && no_of_opened_child_issues == 0) {
IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:]);
// Get access to the Jira comment and component manager
CommentManager commentManager = ComponentAccessor.getCommentManager();
// 61 is the ID of 'Done' trantion in Non-code Sequenced Workflow which supports Epic issue types
IssueService.TransitionValidationResult validationResult =
issueService.validateTransition(user,
epic.id, 61 as Integer, issueInputParameters)
def errorCollection = validationResult.errorCollection
if (! errorCollection.hasAnyErrors()) {
issueService.transition(user, validationResult)
// Create a comment on the issue
def comment = "Moving this epic to 'Done' since all the child issues are closed!! Please feel free to re-open it if it is still an active epic. ";
commentManager.create(epic, user, comment, true);
}
}
}
}
//End of the scripts;
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.