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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

364 views 0 6
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