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

Behaviours Plug-in - Setting default value on custom field Edited

i added one behaviour script to pre-populate a custom field (single select list) with a default value. still its not working, not prepopulating on the screen.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.user.ApplicationUser;
import static com.atlassian.jira.issue.IssueFieldConstants.*
import org.apache.log4j.Level
import org.apache.log4j.Logger

Logger log = Logger.getLogger("ScriptLogger");

log.debug "*********** I am being called for this action: " + getActionName()

if (getActionName() != "Create") {
return // not the initial action, so don't set default values
def zscm = getFieldByName("ZSCM Access")
def zscmoptionsManager = ComponentAccessor.getOptionsManager()
def zscmcustomFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = zscmcustomFieldManager.getCustomFieldObject("customfield_16251")
def zscmconfig = customField.getRelevantConfig(getIssueContext())
def zscmoptions = zscmoptionsManager.getOptions(zscmconfig)
log.debug "******* options found: " + zscmoptions
def zscmoptionToSelect = zscmoptions.find { it.value == "ReadOnly" }
log.debug "******* zscmoptionToSelect = " + zscmoptionToSelect.optionId


In the logs, reading the data correctly 


2019-09-12 05:09:59,067 http-nio-8080-exec-33 DEBUG  309x48375x1 kbd5jb  /rest/scriptrunner/behaviours/latest/validatorsByPid.json [ScriptLogger] *********** I am being called for this action: Create
2019-09-12 05:09:59,068 http-nio-8080-exec-33 DEBUG  309x48375x1 kbd5jb  /rest/scriptrunner/behaviours/latest/validatorsByPid.json [ScriptLogger] ******* options found: [ReadOnly, ReadWrite, NA]
2019-09-12 05:09:59,068 http-nio-8080-exec-33 DEBUG  309x48375x1 kbd5jb /rest/scriptrunner/behaviours/latest/validatorsByPid.json [ScriptLogger] ******* zscmoptionToSelect = 36814

but when creating the issue, ZSCM Access field is showing as "NONE". Please help.

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Keep your team in the loop with Team @mentions in Jira Software!

Hi everyone! My name is Jenny, a Product Manager at Atlassian. After launching Team @mentions in Confluence, we heard a lot of positive feedback from customers that they love how easy it is to @men...

226 views 4 12
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