Update summary field using Groovy

Mike Whitlock December 10, 2013

I am just trying a take the value from a custom field and add it to the current summary. I am using the code below in script runner and in the result I get the new summary that I want, but the issue summary does not actually update. Please help

ComponentManager componentManager = ComponentManager.getInstance()

IssueManager issueManager = componentManager.getIssueManager()

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def issue = componentManager.getIssueManager().getIssueObject("PR047EXE-74")

// gets the value from a custom field which is 123

def QCNum = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'QC Defect ID'};

def QCNumValue = issue.getCustomFieldValue(QCNum);

//add the 123 and a : before the current summary

def newSummary = QCNumValue + ": " + issue.summary;

issue.summary = newSummary;

//in script runner the result is "123: summary" which is exactly what I want the summary to update to but it never updates... it just stays "summary" --- please help

1 answer

1 accepted

0 votes
Answer accepted
JulianA
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.
December 10, 2013

Maybe this will work for you

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
 
void setSummary(String key,String newSummary) {
IssueManager im = ComponentAccessor.getIssueManager();
        MutableIssue issue = im.getIssueObject(key);
        issue.setSummary(newSummary);
        issue.store();
}
 
setSummary("CD-4","Insert your Summary");

David Willson May 14, 2019

Doesn't work

 issue.store();

is deprecated.

Suggest an answer

Log in or Sign up to answer