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?
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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.