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

How to prepopulate default values for Single select Custom field based on group using groovy

I have the Custom field as ZSCM Access which contains the Options such as ReadWrite and ReadOnly. 

Its working, but in the screen, not assigning the default value for custom field "ZSCM Access"

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 com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
Issue issue = issue
import static com.atlassian.jira.issue.IssueFieldConstants.*
import org.apache.log4j.Level
import org.apache.log4j.Logger

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

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 optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def zscmcustomField = zscmcustomFieldManager.getCustomFieldObject("customfield_16251")
def zscmconfig = customField.getRelevantConfig()
def zscmoptions = zscmoptionsManager.getOptions(config)
log.debug "******* options found: " + zscmoptions
def zscmoptionToSelect = zscmoptions.find { it.value == "ReadOnly" }
log.debug "******* zscmoptionToSelect = " + zscmoptionToSelect.optionId
log.debug "*********** create screen: " + getFieldScreen()
if (getFieldScreen().name == "ZS Gov Issue Screen") {


//def zscmcustomField = zscmcustomFieldManager.getCustomFieldObject("zscm.getfieldByID")

when i use the above it throws error as"

java.lang.NullPointerException: Cannot invoke method getRelevantConfig() on null object

0 answers

Suggest an answer

Log in or Sign up to answer

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