Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Summary via Groovy Script doesn't work

Michael Madsen March 30, 2023

I need to slightly change the summary on a lot of issues. So I created a workflow with an action to do this and I created the following postfunction script:

 

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.event.type.EventDispatchOption

IssueManager im = ComponentAccessor.getIssueManager()

MutableIssue currentIssue = im.getIssueObject(issue.key) as MutableIssue

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

String summary = issue.getSummary()

String newSummary = ""

log.warn("Summary: "+summary)

if (summary.endsWith("(Alfa)")) {

newSummary = summary.replaceAll("\\(Alfa\\)","(XX)")

log.warn("New summary: "+newSummary)

currentIssue.setSummary(newSummary)

def changedIssue = im.updateIssue(loggedInUser, currentIssue, EventDispatchOption.ISSUE_UPDATED, false)

log.warn("Updated: "+changedIssue.key)

} else {

log.warn("Nothing to do")

}
The jira issue does NOT change summary. But in the issues history it is stated as if it did!?
I can't figure this out.
Any help would be much appreciated.

2 answers

0 votes
Nic Brough -Adaptavist-
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 31, 2023

If you're using a recent version of Scriptrunner to run the scripts, you can use HAPI to simplify the script:

 

def issue = Issues.getByKey('SR-1') as MutableIssue

issue.set {
setPriority('Highest')
setSummary('my new summary')
}

issue.store()
Michael Madsen March 31, 2023

I'm using 7.6.0 and it doesn't like 

Issues.getByKey
0 votes
Kristján Geir Mathiesen
Community Champion
March 30, 2023

Hi @Michael Madsen and to do some expectation management: I will am not a coder and probably won't solve your problem :)

Have you tried asking chatPBT?

@Rodney Nissen had an interesting article yesterday about that. Check it out and let us know how it went. Of course try the code out in a test environment and all that.

HTH,
KGM

Michael Madsen March 30, 2023

ChatGPT is clueless

Nic Brough -Adaptavist-
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 31, 2023

Yep, I've seen it asked around 400 Jira questions, including 50 that were coding, it only gave one that wasn't subtly or horribly wrong, and in the code, invented APIs and calls that simply don't exist.

It's not a bad idea, I'd use it, but only after it's been trained on a subject with a decent dataset (and that means "not Stackoverflow" for a lot of subjects, as there's a lot of really bad answers there).   It certainly has not been trained on Atlassian stuff yet. 

But there are people working on it.

Suggest an answer

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

Atlassian Community Events