Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,190
Community Members
 
Community Events
184
Community Groups

update summary through scripted post-function

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.
Mar 28, 2023 • edited

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 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.
Mar 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.
Mar 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