Update issue status with IssueInputParameters does not work

I want to update the status from all issues in a proejct with this code, but it doesnt work:

But if i just update the description this works fine, but not for the status.
I tried different ids but nothing helped.

 

 Collection<Long> issueIds = getIssuesIdsFromProject(clonedProject);
IssueService issueService= ComponentAccessor.getIssueService();
for(Long id:issueIds){
MutableIssue issue=getIssueFromId(id);

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setStatusId("1");
UpdateValidationResult updateValResult = issueService.validateUpdate(currentUser, issue.getId(), issueInputParameters);

if(updateValResult.isValid()){
IssueResult updateResult = issueService.update(currentUser, updateValResult);

}else{
throw new RuntimeException("Status for Issue" + issue.getKey() + "not valid");
}

}

 

Is this even possible with the setStatusId Method or do i need to traverse all transtion actions which would be much more effort to implement?

1 answer

0 vote
Alexey Matveev Community Champion Nov 08, 2017

Hello, 

You cant not use setStatusId to transition issue. Your code would look like that:

def issueInputParameters = issueService.newIssueInputParameters()
            issueInputParameters.with {
                setComment("Comment")
                setSkipScreenCheck(true)
            }
            def validationResult = issueService.validateTransition(user, issue.id, 12, issueInputParameters)
            if (validationResult.isValid()) {
                def issueResult = issueService.transition(user, validationResult)
                if (! issueResult.isValid()) {
                    log.warn("Failed to transition task ${destIssue.key}, errors: ${issueResult.errorCollection}")
                }
            } else {
                log.error("Could not transition")
            }

 If your desired status does not have a direct transition to the required status you need to go through all transitions to reach it.

Actually you can create transitions from all statuses to required status . Choose in the workflow settings From status: Any status To status: <your status>.In this case you can always go from any status to the required status. Also add Hide transition from user condition to hide these transitions Jira users.

Ok thank you for your answer.

Is this programmatically possible with java to create new transitions at runtime?

The problem is that is should work for any workflows. So i dont know which actions are available to reach the state.

Or is there a way to get all outgoing transitions with the corresponding actions from the current status of the issue ?
I think this would be the easiest approach to solve my problem.

Alexey Matveev Community Champion Nov 08, 2017

Yes, you can get all outgoing transitions. The code would be like this

IssueWorkflowManager issueWorkflowManager = ComponentAccessor
.getComponentOfType(IssueWorkflowManager.class);

def actions = issueWorkflowManager.getAvailableActions(issue, user) 

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,296 views 14 20
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