ScriptRunner Behaviours - removing option from a select list permanently changes configuration?

Greg Hoggarth March 17, 2020

Background:
We've painted ourselves into a little bit of a corner with the issue types we are using. We have Issue and External Issue which are used for internal vs customer issues for our company's main software product. Recently we added GUI Issue, and now we want to have External GUI Issues.

We've decided the best way to do this is just to re-use an existing "GUI Sub-component" custom field on the External Issue type, where when selected it will update some of the field templates to contain GUI stuff. The workflows between all of these issue types are identical, it's just there's a few fields difference between them.

So, the GUI Sub-component field is a select list which traditionally had has 5 options in it - when you create a GUI Issue, the component will be either X or Y, and then the Sub-component will further narrow down the choices with A, B, C, D or E.

Aim:
Now that we are using this field for External Issues, we want it to have the A-E options and also X and Y, but when a GUI Issue is created hide the X and Y options from the select list because they should never be selected in that case.

Problem:
So I've been using Script Runners - Behaviour module to achieve this.

I have a script that seems to work, except that when it runs it appears to be changing the actual configuration of the custom field select list.

When I go to create an External Issue all options A-E and X and Y show up in the list. If I change to a GUI Issue the list is timmed down to just A-E and X and Y are removed as expected. But then if I go back to create an external issue, it is only showing A-E and X and Y are nowhere to be found.

If I go into the custom field configuration and look at the options available on the select list, only A-E are now appearing, and X and Y have been deleted! This is very unexpected, initially I thought maybe another Jira admin removed them (which would be really unlikely as I'm the primary admin) but I've since shown that it seems to be the Behaviour script that is removing these items.

Only they're not fully removed - if I go to add option X back into this list, it gets added as element 6, but also the original X and Y re-appear in slots 7 and 8. So it seems like they're not 'properly' removed from Jira?

I've done a full re-index of the database and the behaviour is the same.

Here's my script, which is in the Initialiser for these issue types in the relevant project:

if (getActionName() == "Create")
{
if (getFieldById(ISSUE_TYPE).getFormValue() == 11202) //11202 is GUI Issue IssueType
{
/* X and Y are treated as top-level Components for GUI Issues.
* Therefore for GUI Issues, remove X and Y from the GUI Sub-component field */
def GUIfield = getFieldByName ("GUI Sub-component")
def GUIcfield = customFieldManager.getCustomFieldObjectByName("GUI Sub-component")
def fieldConfig = GUIcfield.getRelevantConfig(getIssueContext())
def options = ComponentAccessor.getComponent(OptionsManager).getOptions(fieldConfig)

options.removeAll {it.value in ['X', 'Y']}
GUIfield.setFieldOptions(options);
}
}

Any ideas why this would apparently be changing the actual custom field configuration? Any suggestions for how to do this instead?

We're on 5.6.13.1-p5 for ScriptRunner and Jira Software (Hosted) 8.5.1

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events