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

This widget could not be displayed.
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 (...) {
    ....
}
This widget could not be displayed.

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

505 views 3 18
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