Script Runner to update custom field for workflow transition

Hi

 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

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

Hi,

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 like:log.info("...") 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
	at Script262.run(Script262.groovy:11)

 

 

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

Hey Vijaya,

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

regards, Thanos

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.

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!

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you