update summary through scripted post-function

WindHub Support March 28, 2023

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?

2 answers

1 accepted

1 vote
Answer accepted
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 28, 2023

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.

 

WindHub Support March 28, 2023

you were correct. Thanks a lot!

Graham Twine
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 22, 2023

This just needs to happen before the The "Index Issue" Post function.

The order things happen in post functions is somewhat important

Like WindHub Support likes this
0 votes
Ian Carlos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 28, 2023

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!

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 28, 2023

Both will return the same object. If this was not working, there would be a nullpointer exception in runtime.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
4.20.11
TAGS
AUG Leaders

Atlassian Community Events