You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.