I need a listener ,which will run whenever a new issue is created in a perticular project and will add the priority defined value and few other custom fields (single selection from list) with the provided value for the custom field in the created issue.
I used the script of "update a single select custom field " from the scriptrunner library but it is throwing error when adding as custom script for the listener.
Could you please suggest a script where we can declare the value of many custom field with single select list type with defined value.
I have used the below script :(added the project and create issue as event )
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import groovy.json.JsonSlurper
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.*
import com.atlassian.jira.issue.ModifiedValue
// the name of the custom field (single select list type)
final customFieldName = 'L2 Risk Type'
// the value of the new option to set
final newValue = 'Data'
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"
def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issue))
def optionToSet = availableOptions.find
{ it.value == newValue }
assert optionToSet: "Could not find option with value $newValue. Available options are ${availableOptions*.value.join(",")}"
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), optionToSet), new DefaultIssueChangeHolder())
error in the last line of the script : unable to resolve class DefaultIssueChangeHolder())
We did not mentioned the issue key because , we do not want to apply it only on a particular issue, whenever issue is created it should run and add the changes in the issue created.
Thanks & Regards,
Anunna