Forums

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

Groovy Script Help - append customfield value within summary

Michael
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 20, 2020

Hello everyone,

I'm trying to use a groovy script post function to append a "drop down single select" custom field's value within an issue's summary during issue creation.

Example:

Issue summary = "test"

Custom "drop down single select" field value = "help ticket"

Resulting summary I'm trying to achieve = "Help Ticket - test"

I've experimented with the following (non-script runner) groovy script, but with no luck:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10502")
def cFieldValue = issue.getCustomFieldValue(cField)
def selectedValue = ((LazyLoadedOption)cFieldValue).getValue()

issue.setSummary(cFieldValue + " - " + issue.summary);

Can anyone help me? Any help / suggestions would be greatly appreciated!

Thanks,

Michael

1 answer

1 accepted

0 votes
Answer accepted
Michael
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.
April 9, 2020

For anyone who is interested in knowing the answer to this, a local dev helped me figure this out with the following groovy script:

 

import com.atlassian.jira.issue.*;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;

def issueManager = ComponentAccessor.getIssueManager();
//We need a mutable issue for being able to modify its attributes
MutableIssue missue = issueManager.getIssueObject(issue.getKey());

//We change the issue summary
String created = issue.getCreated().toString();
//This removes the seconds and milisenconds. To remove only the milisencos use lastIndexOf('.') instead
missue.setSummary(issue.getSummary() + " - whatever-you-want-to-append-here");

//Now we save the change
issueManager.updateIssue(user, missue, EventDispatchOption.DO_NOT_DISPATCH, false);

Suggest an answer

Log in or Sign up to answer