Automatic issue transitions between steps

I'm trying to move issue from "Resolved" to "Close" automaticly. I'm using the following code:

public static void issueTransition(Issue issue) {

IssueService issueService = ComponentManager.getInstance().getIssueService();

IssueService.IssueResult transResult;

int actionId = 21;

User user = ComponentManager.getInstance().getUserUtil().getUser("john.d");

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

issueInputParameters.setAssigneeId(user.getName());

issueInputParameters.setSkipScreenCheck(true);

JiraWorkflow workFlow = ComponentAccessor.getWorkflowManager().getWorkflow(issue);

Status status = issue.getStatusObject();

com.opensymphony.workflow.loader.StepDescriptor currentStep = workFlow.getLinkedStep(status);

List<ActionDescriptor> actions = currentStep.getActions();

for (ActionDescriptor actionDescriptor : actions) {

if (actionDescriptor.getName().equals("Close")) {

actionId = actionDescriptor.getId();

log.debug(" actionID close "+ actionId);

}

}

TransitionValidationResult transitionValidationResult = issueService.validateTransition(user,issue.getId(), actionId,issueInputParameters );

if (transitionValidationResult.isValid()) {

IssueResult transitionResult = issueService.transition(user, transitionValidationResult);

if (!transitionResult.isValid()) {

// Do something

log.debug(" !transitionResult.isValid() ");

}

}else

log.debug(" transitionValidationResult FAILED ");

}

The TransitionValidationResult keep returning false.

I get the following message:

[It seems that you have tried to perform a workflow operation (Close) that is not valid for the current state of this issue (TS-10). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]

There is no changes in history.. What do i missing?

3 answers

1 accepted

This line fixed it...:

ComponentManager.getInstance().getJiraAuthenticationContext().setLoggedInUser(user);

Thanx anyway:)

0 votes
Renjith Pillai Community Champion Jun 12, 2013

Which simple means that the issue that you are attempting to transition does not have a Close transition. It is in some other state.

Since you have a hard-coded value of 21 for actionId, you always attempt to perform this.

And I also guess you are not getting this log printed out "log.debug(" actionID close "+ actionId);" as there are not transitions which are matching 'Close'

The action id is 21. i do get it in the log as well.

also when i look at the issue itself it has the close transition for sure...

Where did you deploy it? How to use the script. Can you guide .



Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,139 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot