ScriptRunner, post-function script, changing issue security by custom-field value, how?

Creating: "Custom script post-function"

import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;


GroupManager groupManager = ComponentManager.getComponentInstanceOfType(GroupManager.class)

if (cfValues['selectBoxCustomField']?.value == 'Value1') {
} else if (cfValues['selectBoxCustomField']?.value == 'Value2') {
} else if (cfValues['selectBoxCustomField']?.value == 'Value3') {
} else if (cfValues['selectBoxCustomField']?.value == 'Value4')) {

cfValues['selectBoxCustomField']?.value == 'Value1' fires exception. How can I retrieve "selectBoxCustomField" value?  

2 answers

1 accepted

0 vote
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Name of select box field")

def optString = issue.getCustomFieldValue(cf)?.value
if (optString == "Value") {
else if (...) {

Thank you! 

I've just found solution myself, but yours is shorter:


import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def textFieldCf = customFieldManager.getCustomFieldObjectByName("GRS area")
def cfvalue = issue.getCustomFieldValue(textFieldCf)

String value = cfvalue.toString()

if (value == 'value1') {
} else if (value == 'value2') {


that will fail when there is no option set... so mine uses ?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

134 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you