Forums

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

Use scriptrunner to dynamically populate a custom field (single-select list) with options

Mark Johnson October 1, 2022 edited

Hello.  I'm using Jira Data Center v8.20.

Will someone please provide the Scriptrunner code (including the import statements) for adding options to a drop-down list.

I haven't seen much online that shows me how to do this.  I saw something like a 'setoptions' or 'setFieldOptions' method somewhere but can't find it anymore.

Either way, everything I've tried doesn't work.  Either there's no method for my field declaration, at least no method that makes sense to me to set the options, or I'm declaring my drop-down field incorrectly.

Note:  The code can't refer to an issue because the issue has not yet been created.  I'm trying to populate the drop-down list at the point where the initial issue screen is open for user input (before the issue is actually created).

 

Scenario of what I'm trying to do:

When a user opens an issue, only specific projects that belong to them will be listed as options to select.

Example:  If user Mark opens an issue, the drop-down list will be populated ONLY with projects 'M1', 'M2', and 'M3'.  User John's drop-down list will only include 'J1', 'J2', 'J3'.

I know the logic for this.  I'm using case statements. (i.e., case reporter = "Mark" --> drop-down list items = [Mark's projects]).  I only need the code for dynamically setting the options in the drop-down list.  

 

Recap:

1. I have a single select drop-down list (custom field).  When creating it, I only included one option called 'None' in order to create the field.  The other options need to be filled dynamically when the user opens an issue.

2. The code can't refer to an issue because one hasn't yet been actually created.

 

Than you in advance.

 

1 answer

1 accepted

3 votes
Answer accepted
Hana Kučerová
Community Champion
October 2, 2022

Hi @Mark Johnson ,

welcome to the Atlassian Community!

I don’t think your approach is correct. I believe what needs to be done is to add all possible options to your custom field and hide some options using Behaviours, when the user opens the form.

Almost the same thing is done here:

https://library.adaptavist.com/entity/dynamic-select

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira service management, jsm webinar, ai in jsm, opsgenie integration, incident management, virtual agent, atlassian intelligence, ai-powered service desk, it operations, atlassian learning, service management webinar, team '25 recap

What’s new in Jira Service Management 🤔

Discover how Atlassian is revolutionizing service management with cutting-edge solutions for AI-powered support, HR Service Management, or DevOps connectivity.

Register here ⬇️
AUG Leaders

Atlassian Community Events