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
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.