Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner to update custom field for workflow transition


 we are creating a workflow and during each transition custom field should be updated to the relevant status

eg: if workflow status moved from new  to Ready to Assesment then custom field should be updated to " In Assesment"

I am trying for issue type = "Task"  wit the below code and it's failing


import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Favourite Fruit")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
    it.toString() == 'Lemons'
issue.setCustomFieldValue(cfSelect, value)
Can you please help on this

5 answers

Nevermind, I figured it out.


The Custom Field I was targeting wasn't getting retrieved due to incorrect Custom Field name.

I bet same issue would be for Vijaya!

any update by @Vijaya on this ? I am facing similar errors. Is her problem solved?

  I am executing the script in post-function of Create Issue.

Hey Vijaya,

Try to move your post function right before the Update change history ... step (3) 

regards, Thanos


I had executed the above and script and it fails. Please see below logs

The following log information was produced by this execution. Use statements"...") to record logging information.

2016-12-22 13:59:20,023 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-12-22 13:59:20,023 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: PT-40, actionId: 21, file: <inline script>
java.lang.NullPointerException: Cannot invoke method getRelevantConfig() on null object



Please see the pic the flow I am using. Please let me  know whether it's right or not

import com.atlassian.jira.component.ComponentAccessor

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("My CF")

def cfConfig = cfSelect.getRelevantConfig(issue)

def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == 'The Value I want to set'

issue.setCustomFieldValue(cfSelect, value)

Ji Vijaya,

I cannot see something wrong in your code, apart from the 

def cfConfig = selectCf.getRelevantConfig(issue)

which should be 

def cfConfig = cfSelect.getRelevantConfig(issue)

if your post function is before the store in the database step (or something similar) and of course an option with name Lemons is valid, then this should just work. 

regards, Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

How we use Jira Service Management for our recruitment process! - Part 2

It is never about setting up a process and being done with it. Rather, the focus should always be on optimizing it for the best outcomes. Thus, we didn’t stop at setting up JSM for our recruitment pr...

216 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you