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

0 votes
Accepted answer
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 Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

320 views 0 1
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