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

Update Summary field with the "Execute a ScriptRunner script" action in Automation for Jira.

Matt Nolley May 5, 2021

I am attempting to build an Automation for Jira rule that identifies the presence of a specific string in an Issue's Summary upon creation, assigns Issues that match to a particular individual, and then updates the Issue's Summary field to replace the string with another. 

The first two are no problem, but, as I do not see a way to achieve the final step with Automation for Jira's "Edit issue" action, I'm attempting to update the Issue's Summary field with an "Execute a ScriptRunner script" action instead.  While the script appears to run fine, the Issue's Summary field is never actually updated as a result.

My code is:

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue currentIssue = im.getIssueObject(issue.key) as MutableIssue;

def originalSummary = currentIssue.getSummary();

def trimmedSummary = originalSummary.minus("[originaldummyvalue]");

def newSummary = '[new-dummy-value]' + trimmedSummary;

currentIssue.setSummary(newSummary);

I've used the addMessage() function to log the script's progress and verify that  newSummary contains the expected string value at the time it's fed to currentIssue.setSummary(), but the Issue's Summary field remains unchanged.

Is there a specific step that needs to be taken to force the updated value to be persisted in the database?

4 answers

2 accepted

1 vote
Answer accepted
Erik Buchholz
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 5, 2021

Hi @Matt Nolley ,

yes, setSummary sets the string only to the MutableIssue variable and does not save it to the database. To save the changes to the database use

IssueManager#updateIssue(ApplicationUser user, MutableIssue issue, EventDispatchOption option, boolean sendMail)

e.g.

IssueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

I'm not sure if you need to re-index the issue after that manually. In most cases I use post functions or similar workflow scripts that do both actions for the _issue_ variable.

You can try if the scriptrunner action in automation for jira does the same for the _issue_variable, but this is in many cases no MutableIssue but only an Issue.

Regards
Erik

1 vote
Answer accepted
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2021

Hi @Matt Nolley ,

yes, please try something like:

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 trimmedSummary = originalSummary.minus("[originaldummyvalue]")
def newSummary = '[new-dummy-value]' + trimmedSummary;
currentIssue.setSummary(newSummary);

im.updateIssue(loggedInUser, currentIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
2 votes
Matt Nolley May 5, 2021

So...I almost immediately discovered I was wrong about not being able to solve my issue with Automation for Jira's "Edit issue" action.  The smart value "{{issue.summary.replace("[originaldummyvalue]", "[new-dummy-value]")}}" took care of my need.

However, I still remain curious as to why my script's changes didn't stick.

0 votes
Michael Madsen March 30, 2023

The above Accepted Answer from Hana Kučerová is correct, but if you want to actually update the issue, you need to change:

EventDispatchOption.DO_NOT_DISPATCH

to

EventDispatchOption.ISSUE_UPDATED

 or something other than DO_NO_DISPATCH

Suggest an answer

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

Atlassian Community Events