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.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
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

231 views 1 2
Join discussion

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