I am trying to create a scripted post-function to update the summary by adding a PREFIX and a SUFFIX to the original summary.
By navigating through some other posts I got to this code:
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue currentIssue = im.getIssueObject(issue.key) as MutableIssue
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def originalSummary = currentIssue.getSummary()
def newSummary = "PREFIX" + "-" + originalSummary + "-" + "SUFFIX"
currentIssue.setSummary(newSummary)
im.updateIssue(loggedInUser, currentIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
when I test it in the "Scripted (Groovy) Operation on Issue Post-function" it seems to work fine as it actually changes the summary.
but when I try the transition, the Summary field shows to be updated in the issue's history but the actual Summary of the issue remains unchanged.
Does anyone know what I might be doing wrong here?
I think I might have an idea. You should already be getting the MutableIssue in binding.
What this does now, I think, is that it updates the issue, and then the workflow transition updates the issue again with the "old" data, thus overwritting the summary back.
Don't get a new issue object, use just the binding variable, so the whole script could look as simple as this:
issue.setSummary("PREFIX"+"-"+issue.getSummary()+"-"+"SUFFIX")
And no need to use IssueManager to update the issue - the workflow transition will do that if you place the post-function at the beginning of the order.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This just needs to happen before the The "Index Issue" Post function.
The order things happen in post functions is somewhat important
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try changing
MutableIssue currentIssue = im.getIssueObject(issue.key) as MutableIssue
By
MutableIssue currentIssue = im.getIssueObject(issue.id) as MutableIssue
Let me know if it worked!
Hope it does!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Both will return the same object. If this was not working, there would be a nullpointer exception in runtime.
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.