Hi Atlassians,
Inside my postfunction, I'm using IssueService.IssueResult transition method in order to transition an issue through workflow.
As specified in the documentation, the issue will be saved and re-indexed and the transition will be made.(https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/bc/issue/IssueService.html#transition(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult) ).
As I understand from that, there is no need to update the issue by code as this method will do it.
In my code, I noticed that the transition is happening (by checking History tab) but the issue is not saved (Status is not modified). I used to put issueManager.updateIssue (kindly ckeck highlighted line in the below code) after it in order to force updating the issue.
My question is: Why implementing IssueService.IssueResult transition is not enough to save the issue after transitioning it?
My code is the following:
TransitionValidationResult transitionValidRes = issueService.validateTransition(authenticationContext.getUser().getDirectoryUser(),issue.getId(),configAction.getId(), issueInputParameters);
log.debug("Current Status of the issue: " + issue.getStatusObject().getName());
log.debug("Action ID: " + configAction.getId());
if (!transitionValidRes.isValid())
{
Iterator<String> ite = transitionValidRes.getErrorCollection().getErrorMessages().iterator();
StringBuilder sb = new StringBuilder();
while (ite.hasNext())
{
sb.append(ite.next());
sb.append("\n");
}
throw new Exception(sb.toString());
}
ErrorCollection transitionErrorCollection = issueService.transition(authenticationContext.getUser().getDirectoryUser(), transitionValidRes).getErrorCollection();
if (transitionErrorCollection.hasAnyErrors())
{
log.error(transitionErrorCollection.toString());
}
else
{
log.debug("New Status of Issue: " + transitionValidRes.getIssue().getStatusObject().getName());
}
issue.setStatusObject(transitionValidRes.getIssue().getStatusObject());
issueManager.updateIssue(authenticationContext.getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false);
Thanks,
Rosy
It works by running transition in a new thread from a listener script.
Thread.start({
// your groovy code to run transition
})
If you want to run this at the "issue created" step, you will need to apply an additional tricks to check the workflow is fully initialized before runing your transition:
workflowEntries = ComponentAccessor.getOfBizDelegator().findByAnd("OSWorkflowEntry", FieldMap.build("id", issueObject.getWorkflowId()))
workflowState = workflowEntries[0].get("state")
workflowState must be equal to 1 in order to apply any transition.
You might need to do a "while" loop to wait for the workflow state to change from 0 to 1. (few millisec)
I have the same question. I have been struggling to get this to work, without success, as a listener for a couple of days now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nic.
However, when I checked the code inside Fast Track Script Runner, I noticed that the same method is being used: issueService.transition
WorkFlowUtils.groovy:
public static Issue actionIssue(String additionalScript, MutableIssue theIssue, Integer actionId, User user, Map scriptParams = [:]) {
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = new IssueInputParametersImpl([:])
scriptParams.put("issueInputParameters", issueInputParameters)
ConditionUtils.doAdditional(additionalScript, theIssue, scriptParams)
issueInputParameters = scriptParams['issueInputParameters'] as IssueInputParameters
def validationResult = issueService.validateTransition(user, theIssue.id, actionId as Integer, issueInputParameters)
ErrorCollection errorCollection = validationResult.errorCollection
if (errorCollection.hasAnyErrors()) {
// We used to carry on because sometimes these seem spurious. More investigation needed.
log.error (errorCollection)
log.error ("Not attmpting transition")
return null
}
errorCollection = issueService.transition(user, validationResult).errorCollection
if (errorCollection.hasAnyErrors()) {
log.error (errorCollection)
}
else {
log.info ("Transitioned issue $theIssue through action \"$actionId\"")
}
// reload issue
theIssue = ComponentAccessor.getIssueManager().getIssueObject(theIssue.id)
Status finalStatus = theIssue.statusObject
log.debug "Final status: ${finalStatus.getName()} (${finalStatus.id})"
theIssue
}
Thanks,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Generally, trying to transition an issue while another transition is still executing does not work.
What you've got there would probably work fine in a listener, but I've never seen it work in a post-function (in fact, had jobs cleaning up the mess made by people trying to do this)
I do know it can be done - the script runner and jjupin plugins appear to be doing a transition in a post-function, but it's really not as simple as just trying to kick off a new transition using the issue service (I know at least one of those plugins is effectively starting the transtion after the first one ends),
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.