You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi,
Trying to amend a script that transitions linked issues to work with subtasks as I understand that subtask links are treated differently that normal issues links.
If there is already a solution available then happy to use that or could someone please advise how to correct the currrent script:
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
if(issue.issueTypeObject.name == 'Sub-task'){
String userKey = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getKey()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
//def parent = (MutableIssue) issue.getParentObject().
//MutableIssue issueparent = issue.getParentObject() as MutableIssue
def issueparent = ComponentAccessor.getIssueManager().getIssueObject(issue.getParentId())
Issue issue
Integer actionId = 4
IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
TransitionOptions transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
IssueService.TransitionValidationResult result = issueService.validateTransition(currentUser,
issueparent,
actionId,
issueService.newIssueInputParameters(),
transitionOptions)
if (result.isValid()) {
issueService.transition(currentUser, result)
} else {
log.warn result.getErrorCollection().getErrors()
}
}
Thanks
Mike
Hello @ADC UK
What will happen if a Sub-task is transitioned and another Sub-task is not yet completed.
Do you still expect the parent to transition?
If false is used in `buildTransitionOptions(false)` then all conditions, validations and permissions will be verified. If true is used they will all be skipped.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.user.ApplicationUser
if(issue.issueType.name != 'Sub-task'){
return
}
IssueService issueService = ComponentAccessor.issueService
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueInputParameters inputParams = issueService.newIssueInputParameters()
TransitionOptions transitionOptions = buildTransitionOptions(false)
Integer actionId = 4
IssueService.TransitionValidationResult result =
issueService.validateTransition (
currentUser,
issue.parentId,
actionId,
inputParams,
transitionOptions
)
if (result.valid) {
issueService.transition(currentUser, result)
} else {
log.warn result.getErrorCollection().getErrors()
}
TransitionOptions buildTransitionOptions(boolean skipAllChecks) {
TransitionOptions.Builder builder = new TransitionOptions.Builder()
if (skipAllChecks == true) {
builder.skipConditions().skipPermissions().skipValidators()
}
return builder.build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.