Hi, i am recently using the script runner plugin to autoclose suktasks when the parent issue is closed.
Can you tell me the lines to add to force the "Remaning Time" on subtasks to 0 at the same time ?
Thank you.
You can try this.
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.issue.MutableIssue import org.apache.log4j.Category import static org.apache.log4j.Level.DEBUG log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues") log.setLevel(DEBUG) log.debug "debug statements" IssueService issueService = ComponentAccessor.getIssueService() SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager(); if (subTaskManager.subTasksEnabled) { MutableIssue issue = issue // this is only for the IDE log.debug ("issue.statusObject.name: " + issue.statusObject.name) def currentUser = ComponentAccessor.getUserUtil().getUser("muleuser") issue.getSubTaskObjects().each { subtask -> IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); issueInputParameters.setRemainingEstimate(0L); issueInputParameters.setComment("*Réouverte*, car la demande mère a été réouverte.") IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(currentUser, subtask.id, 3, issueInputParameters); if (transitionValidationResult.isValid()){ IssueService.IssueResult transitionResult = issueService.transition(currentUser, transitionValidationResult); if (!transitionResult.isValid()) { transitionResult.errorCollection.errorMessages.each {log.error "Error Message: $it"} transitionResult.errorCollection.errors.each {log.error "Error: $it"} transitionResult.errorCollection.reasons.each {log.error "Reason: $it"} } } else { transitionValidationResult.errorCollection.errorMessages.each {log.error "Error Message: $it"} transitionValidationResult.errorCollection.errors.each {log.error "Error: $it"} transitionValidationResult.errorCollection.reasons.each {log.error "Reason: $it"} } } }
There is a nice documentation on how to use the issueService. If it doesn't work there could be a problem with the transition screen. Take a look here, especially setSkipScreenCheck().
Use issueService and issueInputParameters.setRemainingEstimate()
any idea ?
I had created a simliar script for this a few months ago. Maybe this can help you.
Usage: Create a JQL-Query that matchs the subtasks, you want to edit. Copy that query
Replace ("INSERT HERE YOUR JQL QUERY") with the created Query.
Run the script
import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.bc.JiraServiceContextImpl; import com.atlassian.jira.bc.filter.SearchRequestService; import com.atlassian.jira.bc.issue.search.SearchService; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.search.SearchRequest; import com.atlassian.jira.issue.search.SearchResults; import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.web.bean.PagerFilter; import com.atlassian.query.Query; SearchResults getissuesByJQL(String jql) throws Exception { SearchService serchService = ComponentAccessor.getComponentOfType(SearchService.class); SearchService.ParseResult parseResult = serchService.parseQuery(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), jql); if (!parseResult.isValid()) { throw new Exception("jql is not valid. jql was "+jql); } Query query = parseResult.getQuery(); SearchResults sr = serchService.search(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), query, PagerFilter.getUnlimitedFilter()); return sr; } void setEstimateToNull(String key) { IssueManager im = ComponentAccessor.getIssueManager(); MutableIssue issue = im.getIssueObject(key); issue.setEstimate(0L); issue.store(); } for (Issue issue : getissuesByJQL("INSERT HERE YOUR JQL QUERY").getIssues()) { setEstimateToNull(issue.getKey()); }
Hi Henning and Julian,
Many thanks for your asnwer.
Henning, here is my script, can you help me to apply what you said ?
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.IssueService import com.atlassian.jira.issue.comments.CommentManager import com.opensymphony.workflow.WorkflowContext import org.apache.log4j.Category import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import org.apache.log4j.Category def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "debug statements" log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues") String currentUser = ComponentManager.getInstance().getUserUtil().getUser("muleuser").getName() WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection subTasks = issue.getSubTaskObjects() if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { log.debug ("issue.statusObject.name: " + issue.statusObject.name) workflowTransitionUtil.setIssue(it); workflowTransitionUtil.setUsername(currentUser); workflowTransitionUtil.setAction (3) // 3 == REOPEN ISSUE issueInputParameters.setRemainingEstimate(3) // Add a comment so people have a clue why the child has been closed CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class); String comment = "*Réouverte*, car la demande mère a été réouverte."; commentManager.create(it, currentUser, comment, true); // validate and transition issue workflowTransitionUtil.validate(); workflowTransitionUtil.progress(); } }
Hi,
i dont know how to use issueService and issueInputParameters.setRemainingEstimate()
You are really Good, it works fine.
Another question : if I want set the estimate to 2h for example ?
I wrote setRemainingEstimate(2h) but i doesnt work
it doesnt work
Try setRemainingEstimate('2h')
It looks like you're new here. Sign in or register to get started.