Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner script to set select option field based on "isUserInGroup"

Kevin Verheyden
Contributor
July 22, 2019

Hi,

I'm trying to set an option in a select field if the reporter is in a specific group but I always get this error.

java.lang.NullPointerException: Cannot set property 'Segmentation' on null object

I tried multiple ways but always with a similar error. This is the latest version I have:

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def groupManager = ComponentAccessor.getGroupManager()
def segment = getFieldById("Segmentation")
def reporter = issue.getReporter()

if (groupManager.isUserInGroup(reporter, "sales-segment-KIA"))
{
segment.setFormValue(13500)
}


1 answer

0 votes
Tarun Sapra
Community Champion
July 22, 2019

Hello @Kevin Verheyden 

To set the option, can you use optionsManager to get the list of option and then set the right option.

https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html#_formfield_setfieldoptions_iterable

Kevin Verheyden
Contributor
July 22, 2019

By set I mean select it not add an option.

Tarun Sapra
Community Champion
July 22, 2019

Hello @Kevin Verheyden 

The example is also about setting a specific option on the select list custom field, the code in the example will not a new option to the select list rather it will fetch the exact option object based on the option name you supply in the code

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events