Status is not updated after performing transitionResult = issueService.transition

Mouna Hammoudi August 12, 2022

I would like an issue to be automatically transitioned from the following statuses: 

  • From Open to Fixed 
  • From Fixed to Tested 
  • From Tested to Completed 

The problem is that the status of my issue does not get updated even after executing the line 

    def transitionResult = issueService.transition(currentUser, transitionValidationResult)
 The log.warn statement still shows the issue OPEN all the time even after executing issueService.transition, this is weird because this status should be changed to "Fixed", then "Tested" and then "Completed". This is what gets printed after executing the issueService.transition statement, notice that the status of the issue is still opened.
2022-08-13 00:54:54,877+0200 https-openssl-nio-443-exec-14 WARN mouh 54x25796x1 1uq4h23 10.248.75.214 /secure/CommentAssignIssue.jspa [c.o.scriptrunner.runner.ScriptBindingsManager] MOUNA 13 IssueConstantImpl[[GenericEntity:Status][sequence,4][statuscategory,4][name,Open][iconurl,/images/icons/statuses/open.png][description,null][id,1]]
I should be updated and should not always be "Opened". Here is my code below. Is there anything I am doing wrong?
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import java.util.HashMap;
import java.util.List;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.issue.IssueService.IssueValidationResult
import com.atlassian.jira.user.ApplicationUser


def log = Logger.getLogger("atlassian-jira.log")
if (issue.getStatus().getSimpleStatus().getId().equals("1")) {
log.warn("MOUNA 1");
int transitionFromOpentoFixed = 71;
int transitionFromFixedToTested = 111;
int transitionFromTestedToCompleted = 131;
log.warn("MOUNA 100 transitionFromOpentoFixed " + issue.getStatus());
transition(transitionFromOpentoFixed);
log.warn("MOUNA 101 transitionFromFixedToTested " + issue.getStatus());
transition(transitionFromFixedToTested);
log.warn("MOUNA 102 transitionFromTestedToCompleted " + issue.getStatus());
transition(transitionFromTestedToCompleted);
}


void transition(int transitionToBeDone) {
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn("MOUNA 5 STATUS " + issue.getStatus());
log.warn("MOUNA 6 ");
String issueKey = issue.getKey()
log.warn("MOUNA 7 ");
IssueService issueService = ComponentAccessor.getIssueService()
log.warn("MOUNA 8");
def transitionValidationResult
log.warn("MOUNA 9 ");
def issueInputParameters = issueService.newIssueInputParameters()
transitionValidationResult = issueService.validateTransition(currentUser, issue.id, transitionToBeDone, issueInputParameters)
log.warn("MOUNA 10");
if (transitionValidationResult.isValid()) {
log.warn("MOUNA 11 transition is valid");
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
log.warn("MOUNA 12 ");
if (transitionResult.isValid()) {
log.warn("MOUNA 13 " + issue.getStatus());
} else {
log.warn("MOUNA 14 transitionResult not valid");
}
}
}

1 answer

1 accepted

1 vote
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 12, 2022

Hi @Mouna Hammoudi 

 

You can use the postfunction fasttrack transition for this use case or even better an automation for JIRA.

https://docs.adaptavist.com/sr4js/latest/features/workflows/post-functions/built-in-post-functions/fast-track-transition-an-issue

Is there any screen in the transition ?

 

Regards

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 12, 2022

Do not try to transition an issue part way through another transition, it makes a complete mess.  As @Florian Bonniec says, use the "fast track" transition option instead.

Suggest an answer

Log in or Sign up to answer