Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How set Custom field value with scriptrunner (Server)



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! 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová Community Leader Jul 27, 2021

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").setFieldOptions(options.findAll {it.value in ['OTECH']})

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events