Hi,
I created a listener (in groovy, through script runner plugin) which has to transition an issue on assigning the issue to a different user. The transition ("Stop Progress") has two conditions "currentUser = assignee OR currentUser is in group jira_bots".
This is the code of the transition method.
static void transitionIssue(issue, actionId, IssueInputParameters issueInputParameters, log=null, user=null) { log?.debug "Starting transitionIssue" ComponentManager cm = ComponentManager.instance if (!issueInputParameters) { log?.debug "Empty InputParameters, creating new one." issueInputParameters = new IssueInputParametersImpl([:]) } // http://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/IssueInputParameters.html if (!user) { log?.debug "User is null, get one." user = getUser(log) } log?.debug "User is ${user}" log?.debug "Issue.ID is ${issue.id}" log?.debug "ActionID is ${actionId as Long}" // log?.debug "issueInputParameters is ${issueInputParameters.dump()}" // log?.debug "Issue Dump is ${issue.dump()}" def validationResult = cm.issueService.validateTransition(user, issue.id, actionId as int, issueInputParameters) // log?.debug "Validationresult: ${validationResult.dump()}" if (validationResult.isValid()) { log?.debug "validationResult is valid" def transResult = cm.issueService.transition(user, validationResult) log?.debug "Transitionresult: ${transResult.dump()}" if (!transResult.isValid()) { log?.error ("Transition failed.") transResult.errorCollection.errorMessages.each{log?.error "Error Message: $it"} transResult.errorCollection.errors.each{log?.error "Error: $it"} transResult.errorCollection.reasons.each{log?.error "Reason: $it"} } else { log?.info ("Transitioned issue $issue through action \"$actionId\"") } } else { log?.debug "validationResult is NOT valid" validationResult.errorCollection.errorMessages.each{log?.error "Error Message: $it"} validationResult.errorCollection.errors.each{log?.error "Error: $it"} validationResult.errorCollection.reasons.each{log?.error "Reason: $it"} log?.error ("Not attempting transition") } }
This is the resulting log output:
2012-02-20 14:57:34,577 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] Starting transitionIssue 2012-02-20 14:57:34,578 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] Empty InputParameters, creating new one. 2012-02-20 14:57:34,578 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] User is jira_bot 2012-02-20 14:57:34,578 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] Issue.ID is 55491 2012-02-20 14:57:34,578 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] ActionID is 201 2012-02-20 14:57:34,597 http-8443-15 DEBUG htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] validationResult is NOT valid 2012-02-20 14:57:34,599 http-8443-15 ERROR htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] Error Message: It seems that you have tried to perform a workflow operation (Stop Progress) that is not valid for the current state of this issue (INS-5632). The likely cause is that somebody has changed the issue recently, please look at the issue history for details. 2012-02-20 14:57:34,602 http-8443-15 ERROR htietgens [...] /secure/AssignIssue.jspa [eventim.AssigneeListener] Not attempting transition
At the moment my listener tries to perform the transition the assignee is already the new assignee, so the first condition doesn't match. I tried to do the validateTransition() from IssueService with a user in group jira_bots (to match the second condition) but it doesn't work (Error Message: It seems that you have tried to perform a workflow operation (Stop Progress) that is not valid for the current state of this issue (INS-5632). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.). If I add the current user to the group jira_bots the transition takes place.
Should it work or do I have to do something different to perform a transition as a different user?
Thanks Henning
Community moderators have prevented the ability to post new answers.
I got it... if I put a
cm.jiraAuthenticationContext.loggedInUser = user
just before the validateTransition() the transition is validated.
It completely my own code and it's distributed within different classes. It's a little bit difficult to post it. I will add the transition method to the question. Thanks Jamie.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Henning, you might need to post your code. Also is it all your own code or are you using the fast-track transition built-in script?
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.