Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

update custom filed by Custom script post-function



I would like to update custom filed by Custom script post-function  and my script is like below.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.customFieldManager
def escalate = customFieldManager.getCustomFieldObjectsByName("DeployApprove").first()

def optionsManager = ComponentAccessor.getOptionsManager()
def config = escalate.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
def optionToSelect = options.find {
it.value == "yes"
escalate.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(escalate), optionToSelect), new DefaultIssueChangeHolder())


However, this is failed when the custom filed "DeployApprove" is checked "No" already before this script works.


How should I change this script to be changed when the custom field is null or checked "No"?


1 answer

Give this a shot



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def cfManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("DeployApprove")
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {it.toString() == 'Yes'}
issue.setCustomFieldValue(cfSelect, value)

issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

Suggest an answer

Log in or Sign up to answer
Site Admin

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