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.security.groups.GroupManager;

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') {
issue.setSecurityL
} else if (cfValues['selectBoxCustomField']?.value == 'Value2') {
issue.setSecurityLevelId(10105)
} else if (cfValues['selectBoxCustomField']?.value == 'Value3') {
issue.setSecurityLevelId(10104)
} else if (cfValues['selectBoxCustomField']?.value == 'Value4')) {
issue.setSecurityLevelId(10103)
}


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

2 answers

1 accepted

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') {
issue.setSecurityLevelId((long)10715) 
} else if (value == 'value2') {
issue.setSecurityLevelId((long)10705) 
}

 

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

441 views 8 26
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