ScriptRunner update summary from another issue

Dante Labate May 29, 2018

I need help.

 

Could someone help me write a script that changes the summary of another issue.

I have in a customfield the KEY of this issue that I want to change.

 


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


def id_vaga = customFieldManager.getCustomFieldObject("customfield_16057")
def key_value = issue.getCustomFieldValue(id_vaga).toString()


def issueManager = ComponentAccessor.getIssueManager()
def issue1 = issueManager.getIssueObject("${key_value}")

issue1.setSummary("XYZ")

 

2 answers

1 accepted

3 votes
Answer accepted
Alexey Matveev
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 29, 2018

It depends where you add your post function. You could try also this one

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor

def id_vaga = customFieldManager.getCustomFieldObject("customfield_16057")
def key_value = issue.getCustomFieldValue(id_vaga).toString()

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject(key_value);
issue.setSummary("XYZ");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Dante Labate May 30, 2018

tks @Alexey Matveev for your response!

 

But I'm getting the same error as I reported in the comment above.

Alexey Matveev
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 30, 2018

It is a static error. If you run the script, the script would work. Or You could write like this:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor

def id_vaga = customFieldManager.getCustomFieldObject("customfield_16057")
def key_value = issue.getCustomFieldValue(id_vaga).toString()

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject(key_value) as MutableIssue;
issue.setSummary("XYZ");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Dante Labate May 30, 2018

I solved the problem by adding the lines below:

import com.atlassian.jira.issue.MutableIssue

def customFieldManager = ComponentAccessor.getCustomFieldManager()

But this signaling me another mistake

 image.png

image.png

 

Even though I save and trying to execute the transition, the summary of the other issue is not changed (and this error appears in the log)

 

2018-05-30 08:54:46,492 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-05-30 08:54:46,492 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: RH-118, actionId: 111, file: <inline script> groovy.lang.MissingPropertyException: No such property: EventDispatchOption for class: Script1725 at Script1725.run(Script1725.groovy:15)

 

Alexey Matveev
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 30, 2018

Try like this:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def id_vaga = customFieldManager.getCustomFieldObject("customfield_16057")
def key_value = issue.getCustomFieldValue(id_vaga).toString()

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject(key_value) as MutableIssue;
issue.setSummary("XYZ");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Like # people like this
Dante Labate May 30, 2018

IT WORKS !!!!

VERY VERY THANKFUL!

1 vote
Tuncay Senturk
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 29, 2018

Try this one

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor

def id_vaga = customFieldManager.getCustomFieldObject("customfield_16057")
def key_value = issue.getCustomFieldValue(id_vaga).toString()

IssueManager im = ComponentAccessor.getIssueManager();
MutableIssue issue = im.getIssueObject(key_value);
issue.setSummary("XYZ");


Dante Labate May 30, 2018

Tks @Tuncay Senturk for your response!

 

I'm getting this error message when trying to save the script.

image.pngJIRA 7.1.7
I want to use this script in post function.

BBS December 12, 2019

Add the import statement,

 

import com.atlassian.jira.issue.MutableIssue;

Suggest an answer

Log in or Sign up to answer