create linked issue and perform a transition Edited

I'm using the "Clones an issue, and links" post funcion feature.

I want to create a linked issue but not in the first status. Then I want to transition this issue linked.

In "additional issue actions"  I putted this code.

 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl

MutableIssue issue1= issue;
WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue1);
workflowTransitionUtil.setAction(321);
workflowTransitionUtil.validate();
workflowTransitionUtil.progress();


But I t doesn't work .
In the jira Log I'm viewing the following message.


c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TEST-5, actionId: 31, file: null
Caused by: org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction.

 

 

1 answer

Hi Sergio, 

So for this you will need to write a script that will transit the cloned issue after it's creation. 

So in the additional issue actions field you can have something like 

def user = ComponentAccessor.userManager.getUserByKey("admin")

doAfterCreate = {
// 21 is the id of the step you want the issue to move
transitIssue(issue, 21, user)
}


def transitIssue(Issue issue, int actionId, ApplicationUser cwdUser) {
def issueService = ComponentAccessor.getIssueService()

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This is a comment")
issueInputParameters.setSkipScreenCheck(true)

def transitionOptions= new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

def transitionValidationResult =
issueService.validateTransition(cwdUser, issue.id, actionId, issueInputParameters, transitionOptions)

if (transitionValidationResult.isValid()) {
return issueService.transition(cwdUser, transitionValidationResult).getIssue()
}

log.error "Transition of issue ${issue.key} failed. " + transitionValidationResult.errorCollection
}

Hope that helps, please ping me if you have any further questions

Regards, Thanos

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

60 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you