Hello!
Please tell me how to change the status for tasks correctly?
Given:
issueKey = "TEST-1"
currentStatus = "In Progress"
nextStatus = "Done"
So, the transition "InProgress -> Done" has an id = 900. Community documentation recommends using {{IssueService}}, which is what I am trying to do...
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
final String ISSUE_KEY = "TEST-1"
int ACTION_ID = 900
def issueService = ComponentAccessor.getIssueService()
// context of the currentUser
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// getting issue via IssueService
MutableIssue issue = null
def getIssueResult = issueService.getIssue( user, ISSUE_KEY )
if( getIssueResult.isValid() == true && getIssueResult.getIssue() != null )
{
issue = getIssueResult.getIssue()
}
else
{
return "Issue not found!"
}
def params = issueService.newIssueInputParameters()
def transitionValidationResult = issueService.validateTransition( user, issue?.getId(), ACTION_ID, params )
if( transitionValidationResult.isValid() == true )
{
def issueResult = issueService.transition( user, transitionValidationResult )
if( issueResult.isValid() == true )
{
log.debug "valid. Issue is = ${issueResult.getIssue()}"
return issueResult.getIssue()
}
else
{
log?.warn "error"
return issueResult.getErrorCollection()?.getErrorMessages()
}
}
else
{
return transitionValidationResult.getErrorCollection()?.getErrorMessages()
}
"${transitionValidationResult.isValid()}"
and, my result is:
[It seems that you have tried to perform a workflow operation (Resolve) that is not valid for the current state of this issue (TEST-1). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]
But, an issue TEST-1 haves the status "In Progress" and, this issue have the direct step/link to the "Resolved" status! Btw, i can change the status "In Progress" to "Resolved" manually, via IssueService - i got error.
So, how to transit an issues as correctly?
I could not move the task to the next status because it was an ISSUE_CREATED event. That is, at the time of creation of the task - it is not possible to move the task to the next status (but you can do it during the event ISSUE_UPDATED).
def srv = ComponentAccessor.issueService
class ThreadService extends Thread
{
private def srv = ComponentAccessor.issueService
private def threadUser
private Issue issue
public ThreadService(final ApplicationUser user, final Issue issue)
{
super()
threadUser = user
this.issue = issue
}
public void run( )
{
//Thread.sleep(1000); // delay for indexing
ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(threadUser)
// there we can do transition
}
};
if (event.eventTypeId == ISSUE_CREATED)
{
Thread t = new ThreadService(event.user, event.issue)
t.start() // !!! no join for CREATED event !!!
}
else if(event.eventTypeId == ISSUE_UPDATED)
{
//srv.transition( ... )
}
IssueService issueService = ComponentAccessor.getIssueService();
IssueIndexingService issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
TransitionValidationResult validationResult = issueService.validateTransition(loggedInUserName, issue.getId(),
actionId, issueInputParameters);
if (validationResult.isValid()) {
issueService.transition(loggedInUserName, validationResult);
issue.setStatusId(statusID);
ComponentAccessor.getIssueManager().updateIssue(loggedInUserName, issue, EventDispatchOption.ISSUE_UPDATED,
false);
try {
issueIndexingService.reIndex(validationResult.getIssue());
} catch (IndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Collection<String> errors = validationResult.getErrorCollection().getErrorMessages();
for (String error : errors) {
// Logger.getLogger(error);
}
}
Try This, it will work!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
I think your script looks fine, can I check that the ID 900 is the ID of the next status and not the ID of the transition itself?
I think from memory you need to provide the ID of the target status and not the transition itself.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.