Will someone please provide a fix for populating my custom field (single select list) using scriptrunner code?
I'm using Jira Data Center v8.20. I have a custom single select list/drop-down list called “Project To Update”. In the configuration settings for the field, I configured the field with test options (Illustration 1).

Using behaviours (in the Initialiser section), I’m trying to dynamically set the options available in the select list when opening an issue in Jira (BEFORE the issue is actually created). Very simple, short code. For testing, on line 2, I’m just trying to limit the field options for the “Project To Update” field to 2 options (‘Project 1’ and ‘Project 2’). See Illustration 2.

This code (line 3, …setFieldOptions…) is obviously affecting the field, but not as I expected. The field (Project To Update) is empty. See Illustration 3. I'm guessing this may have to do with the way I'm creating the list (line 2), but I don't know how else to set it.

When I comment out line 3 (Illustration 4), the field is populated with the options set in the custom field configuration (Illustration 5).


As stated previously, line 3 is 'getting to' the field, but it's not updating the options list (it's clearing it). I'd really appreciate a resolution to this.
On a less important note, I’m also trying to set the field’s value to ‘Project 1’ (line 4 in the illustrations). Right now, the value is empty, even when the options are available and when only running line 4 (setFormValue). I’d appreciate help with this as well, though fixing the options list is my main goal.
Many thanks,
Mark