Update issue status with IssueInputParameters does not work

huntermike November 8, 2017

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 votes
Alexey Matveev
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.
November 8, 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.

huntermike November 8, 2017

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.

huntermike November 8, 2017

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
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.
November 8, 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 Sign up to answer