Hello,
We are trying to set custom field value(s) for all issues created in a project.
We don't want to use postfunction, since workflow is shared, with other projects and we want this solution to be scalable, instead of creating a copy of a workflow for every project.
Tried to set up custom listener for particular project with following code, but it keeps throwing errors in the console:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("customFieldId=21004")
def cfConfig = cf.getRelevantConfig(issue)
value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'OTECH' }
issue.setCustomFieldValue(cf, value)
I usually don't use scriprunner, but in this particular instance its the only plug in available.
Any help is appreciated!
Hi @Alex Kulichkov ,
this line doesn't seem right:
def cf = customFieldManager.getCustomFieldObjectByName("customFieldId=21004")
I would recommend to replace it with:
def cf = customFieldManager.getCustomFieldObject(21004)
Please check, you are really able to get the custom field object.
Also I believe setting custom field value is not enough, you should also store the value to persist the change to the database.
Thank you Hana,
We fixed the script to be used in combination with behavior, it worked and looks like that.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
// new try
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(21004)
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionToSelectAI = options.find {it.value == "OTECH"}
// mod
getFieldById("customfield_21004").setFormValue(optionToSelectAI.optionId)
getFieldById("customfield_21004").setFieldOptions(options.findAll {it.value in ['OTECH']})
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.