Hi community, looking for some assistance on this one.
Using Scriptrunner Behaviors, when a user selects an option in custom list called "Category" I would like to set an existing value in my custom list field "Group". I'm able to retrieve the Category values without an issue, however I cannot set the Group select list value (by name or by option ID). Can someone please assist in how to set this select list value?
Here is the script:
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
// Define both custom select lists
def category = getFieldByName("Category")
def group = getFieldByName("Group")
// Get the Value of the Category field and Group field
def catval = category.getValue()
log.warn("Category Value: " + catval)
def groupval = group.getValue()
log.warn("Group Value: " + groupval)
// If the Category select list value equals Other
if (catval == "Other"){
// Set the value of the select list to Group option id of 12208 "Test Group"
group.setFormValue(12208)
}
After some research, I was able to resolve this issue. Hope this helps others!
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def authContext = ComponentAccessor.getJiraAuthenticationContext();
def optionsManager = ComponentAccessor.getOptionsManager()
CustomField category = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Category"}
CustomField group = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Group"}
fieldConfig = group.getRelevantConfig(issue)
group1 = optionsManager.getOptions(fieldConfig)?.find{it.value == "Group Name 1"}
group2 = optionsManager.getOptions(fieldConfig)?.find{it.value == "Group Name 2"}
groupother = optionsManager.getOptions(fieldConfig)?.find{it.value == "Unassigned"}
categoryvalue = issue.getCustomFieldValue(category).getValue()
log.debug("Category: $categoryvalue")
//If CustomField 'Category' matches the following values...
if (categoryvalue == "ValueA" || categoryvalue == "ValueB" || categoryvalue == "ValueC" ){
//Set CustomField 'Group' to "Group Name 1"
issue.setCustomFieldValue(group, group1)
log.debug("Group: $group")
}
//If CustomField 'Category' matches the following values...
if (categoryvalue == "ValueD" || categoryvalue == "ValueE" || categoryvalue == "ValueF" ){
//Set CustomField 'Group' to "Group Name 2"
issue.setCustomFieldValue(group, group2)
log.debug("Group: $group")
}
//If CustomField 'Category' matches the following value...
else if (categorycatvalue == "Other" ){
//Set CustomField 'Group' to "Unassigned"
issue.setCustomFieldValue(group, groupother)
log.debug("Group: $group")
}
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.