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

srikanth September 13, 2019

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.setLevel(Level.DEBUG)

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
zscm.setFormValue(zscmoptionToSelect.optionId)
log.debug "*********** create screen: " + getFieldScreen()
if (getFieldScreen().name == "ZS Gov Issue Screen") {
zscm.setFormValue(zscmoptionToSelect.optionId)

 

//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
	at Script262.run(Script262.groovy:11)

0 answers

Suggest an answer

Log in or Sign up to answer