Scriptrunner Behavior changed on Jira 9

Ivan D March 26, 2024

Hello colleagues,

There is a behavior to restrict a select list options, that works on Jira 7 but doesn't on Jira 9 (the 7's clone).

The type checking is passed, the error message is:

Cannot invoke method getRelevantConfig() on null object

Googled reasons point to an issue with a field context, but there is the global context.

Can you please advise.

BR,

Ivan

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2024

Hi @Ivan D

Could you please provide more information on how you are running the test, i.e. when are you trying to trigger the Behaviour? Is it on the Create, Edit or Transition screen?

Please clarify what version of ScriptRunner you are currently using.

Also, it would be beneficial if you could share a screenshot of your Behaviour configuration.

Thank you and Kind regards,

Ram

Ivan D March 26, 2024

Hi Ram,

Is it on the Create, Edit or Transition screen?

On Edit. But getActionName() isn't used.

what version of ScriptRunner

  • SR v5.6.9 at Jira v7.5.0
  • SR v8.24.0 at Jira v9.12.2

share a screenshot of your Behaviour configuration

restrict options.png

BR,

Ivan

 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 30, 2024

Hi @Ivan D

The current code that you are using is applicable for Jira 7. However, from Jira 8 onwards, it will not work as expected.

Since you intend to filter the options from the Select List, I suggest you change your approach to:-

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def sampleList = getFieldByName('Sample List')
def listOptions = []

if (underlyingIssue && actionName == 'null') {
listOptions = ['CEO','COO', 'CTO']
sampleList.setFieldOptions(listOptions)
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

image1.png

From the screenshot of the code you shared in your last comment, I will assume that this Behaviour is configured using the Behaviour Initialiser since no condition is set to determine the filtration.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Ivan D March 31, 2024

Hi Ram,

Thanks a lot!

Actually it was necessary to tune here, besides obvious settings, also

getFieldByName

It was because first I've got the same error message again. It pushed me to the idea that for some reason the script cannot find a context of the Status field by name, so I've tried 

getFieldById("customfield_11129")

and it helped.

Also if() part prevented working (is it needed?) so I removed it. The final view is:

import com.onresolve.jira.groovy.user.FieldBehaviours

import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

//def sampleList = getFieldByName("Status")

def sampleList = getFieldById("customfield_11129") //Status

def listOptions = []

//if (underlyingIssue && actionName == 'null') {

listOptions = ['Активный','Не активный']

sampleList.setFieldOptions(listOptions)

//}

The funny side effect is that with the change of ByName to ById the old script started working too)

 

BR,

Ivan

Suggest an answer

Log in or Sign up to answer