Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Transition parent from sub-task workflow post function

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

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Graham Twine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Sep 02, 2023 • edited

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()

}
TAGS
AUG Leaders

Atlassian Community Events