The code below is supposed to change a custom field (single list) value (approval group) if the summary and description (combined into a string) contains either string, keywords1 and keywords2 (the list of keywords) that correspond to each group defined in the first couple lines. I'm not sure if I'm having a syntax issue or if there is something fundamentally wrong with my listener because it is not firing off.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
var string keywords1 = ["value1","value2",value3"]
var string keywords2 = ["value1","value2",value3"]
def issue = event.issue as Issue
def full_data = issue.Summary + " " + issue.description
def customFieldName = "Assigned Group"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
if (full_data.contains(keywords1))
issueToUpdate.setCustomFieldValue(customFieldName,"Team 1")
if (full_data.contains(keywords2))
issueToUpdate.setCustomFieldValue(customFieldName,"Team 2")
Hi @Matt Dejene ,
Your code seems correct, please try to use this script to update the select list value (update the id) :
def customFieldId = 12503
def customField = customFieldManager.getCustomFieldObject(customFieldId)
def customFieldValue = issue.getCustomFieldValue(customField)
def customFieldConfig = customField.getRelevantConfig(issue)
def cfNewValue = ComponentAccessor.optionsManager.getOptions(customFieldConfig)?.find { it.toString() == "Team 1" }
customField.updateValue(null, issue, new ModifiedValue(customFieldValue, cfNewValue), new DefaultIssueChangeHolder())
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry Im still getting a syntax error for “EOF”, when using var or def for defining the variables for matching keywords. Everything else looks fine. Am I missing something simple?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Matt Dejene is it a warning or an error ? In the console you will get warnings since its a basic java interpreter, but the code will work fine.
Have you tried executing it ? Could you please provide a screenshot if it fails ?
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.