Custom field which updates its options

Rumceisz June 18, 2012

Hi All,

I am investigating a request but I haven't found a clue so far:

we have a Jira and Confluence instance and the user management is common: it is administrated in Jira. We - admins - have a project in Jira where all the project leaders and space admins can submit issues regarding to the Jira and Confluence. Most of the time they submit access rights issues where they ask us to add the developers/testers, etc to a project and/or a space.

We have 2 custom fields in our user access issue type: one is the Confluence spacewhich contain all the existing space names as options. The other is the Jira project which contains all the existing project name as options. Both custom fields are of multi-select type.

So when a project leader requests an issue, just select in these custom fields which project(s) and/or space(s) he want to add the users.

The main problem is that the project leaders and space admins often change the name of their project or space. But the update the options of these 1 custom fields is very cumbersome!

My question is that is there a macro, script, feature which update the options of these custom fields? I mean that this feature run and make a list of the names of existing projects and spaces and updates the 1 custom fields.

Can you please suggest?

Thanks in advance!

Rumi

3 answers

1 accepted

2 votes
Answer accepted
Nic Brough -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.
June 18, 2012

I'd use the Jira database values plugin, and point it at the "project" table inside the same Jira.

See https://marketplace.atlassian.com/plugins/org.deblauwe.jira.plugin.database-values-plugin

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2012

Hi Nic ,

Once i had tried to connect to Jira Database(External) using JDBV plugin but i was not able to connect it , i was able to connect to another external database .

1 vote
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2012

You can also use the Scripted field provided by script runner plugin and write a script which will show all the projects and space in the customfields.

Rumceisz June 18, 2012

Hi Mizan,

I have Script runner plugin, so I opt this solution. Only problem that I don't know the velocity. If it's not a difficult code, can you please help to write?

Thanks in advance!

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2012

Hi Rumi,

I have never used this feature before , but i will try to help you with the script .

First thing is to check if scripted field can be a multiselect list . Try to add a scripted field and check , refer the docs for this .

If you are able to connect to Jira & confluence database with Database values plugin you can even go for it its a free plugin .

Once i tried to connect jira db using JDVP but i was not able to and had to use SQL feed plugin

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2012

is it a multiselect list ? can you paste your script here ? do you see anything related to this field in the logs ?

0 votes
Rumceisz June 19, 2012

Hi Mizan,

thank you for help!

"First thing is to check if scripted field can be a multiselect list . Try to add a scripted field and check , refer the docs for this ."

It's weird...because we have Script Runner plugin but when creating a custom field there is no field type Scripted Field to choose in the list. Is there any other way to add a script to a custom field? I guess to description field...

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2012

In the description only javascript work and using that we cant get spaces from confluence.

Another approach can be to set options to the multiselect field using behaviours plugin.

You will have to create a script which gets all project names and sets it as options to this field using the setFieldOptions(Map map)

Have a look at this example

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2012

Oh , it means you dont have the latest compatible version of the plugin , scripted customfields are available from version 1.8.1

Rumceisz June 24, 2012

Thanks!

I wonder why we don't have the field type "Scripted field". We have an active, licensed Script Runner plugin installed.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2012

You need this version . Is it compatible with your jira version ? What version of jira u have ?

Rumceisz June 24, 2012

I think it is the latest: 1.7.14 - this version we have and no upgrade suggested

Rumceisz June 24, 2012

I see...this is the problem: we have only Jira version 4.3.4
Mizan, you mentioned the Behaviour plugin as a helpful plugin to another solution. I checked and we have this plugin.

Rumceisz June 24, 2012

I try to find another solution, so I gather all the info here in this issue.

Mizan, have you got any different idea?

I summarize the need: I'd like to have a custom field type of multi-select. The options of the custom field would be the current name of all projects of the instance. So it would update the option if a project name would be changed or the options would extend if a new project were created. But when a project were deleted the option must remain.

Mizan, sorry for the disturbance!:)

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2012

Another idea would be to use Behaviours plugin , but i want to know which database your Jira uses (Oracle , MySql , etc) , How many projects in your Jira Instance ?

The Behavior plugiin cannot connect to Oracle by default , you will have to make it compatible with your version of Jira . I have done it see this https://studio.plugins.atlassian.com/browse/JBHV-133 issue.

Adding a behaviour(server side groovy script) to a multiselect customfield might help.

This behaviour will connect to Jira database , fetch all project names and display it in the field .

I have done something similar .

Rumceisz June 25, 2012

Hi Mizan,

I think it's the right track: we have Behaviours plugin. Version: 0.4.7

We use PostgreSQL database

Current number of projects: 185, Jira version: 4.3.4

How did you do that in you Jira?

Rumi

Rumceisz June 25, 2012

Hi Mizan,

let's see..

can I run this script in the Script Runner?

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2012

You can but behaviours and script runner are two different plugin , you wont be able to make a field behave the way you want using script runner ,

i think this is not the correct way there can be a better way , instead of getting the values from database we can directly get it through API , or if you are comfortable with plugin developement you can create a customfield which will behave like a multiselect project picker .

Rumceisz June 25, 2012

It is sad because the main problem that I am not acquianted with plugin development.

So I'm a bit confused: where can I run this script? I only know the script runner interface.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2012

Behaviours plugin provide a similar interface but for each field , you should go through the documentation first .https://studio.plugins.atlassian.com/wiki/display/JBHV/JIRA+Behaviours+Plugin

also see this similar example

then the next thing to do is install the plugin on a test instance then start scripting on a customfield(multiselect list type) this field will show all projects from the jira instance.

Rumceisz June 26, 2012

Hi Mizan,

I installed the Behaviour plugin to my test instance.

I started the test: I wrote a script which result the members of a particular group and then inserted this script to the test behaviuor and accessed to a custom field. But when testing the cutom field doesn't contain the member list as options - so nothing happens.

I attached the pic about the settings and the script. The script works however, I run in script runner.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2012

Create a customfield (Multiselect list) then add the below script as a serverside script to it using behaviours plugin. I have not tested it .

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

import com.atlassian.jira.ComponentManager

FormField projectsField = getFieldById(fieldChanged)

Map fieldOptions = [:]

def projectManager = ComponentManager.getInstance().getProjectManager()
for(p in projectManager.projects) {
    fieldOptions.put(p.name,p.name);
}

projectsField.setFieldOptions (fieldOptions)

Rumceisz July 2, 2012

Hi All, Hi Mizan,

I just upgraded my Jira to version 5 and I implemented the version 2.0.6 of groovyrunner.

Can we turn back to the solution of Script Fields?

Thanks,

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2012

Yup , were you able to see scripted field in the list of Customfields ? add a scripted field and try the script which i provided earlier in some other question .

first try a basic example and see whether the field can be a multi select .

OR the above example of behaviours is also a simple option

Rumceisz July 3, 2012

Hi Mizan,

there is no Multi-select option in the scripted field.

Rumceisz July 3, 2012

Hi Mizan,

I tested it but the multi-select field is empty

Create a customfield (Multiselect list) then add the below script as a serverside script to it using behaviours plugin. I have not tested it .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentManager
FormField projectsField = getFieldById(fieldChanged)
Map fieldOptions = [:]
def projectManager = ComponentManager.getInstance().getProjectManager()
for(p in projectManager.projects) {
fieldOptions.put(p.name,p.name);
}
projectsField.setFieldOptions (fieldOptions)
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2012

Try the below code and check whether you see any options , also enable logging and add some logging to the script. you can enable logging clicking on the enable logging link .

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
 
import com.atlassian.jira.ComponentManager
 
FormField projectsField = getFieldById(fieldChanged)
 
Map fieldOptions = [:]

fieldOptions.put("Proj1","Proj1");
fieldOptions.put("Proj2","Proj2");
fieldOptions.put("Proj3","Proj3"); 
projectsField.setFieldOptions (fieldOptions)

Rumceisz July 4, 2012

Hi Mizan,

where can I put the code?

I insterted in Behaviour and I got this message:

Compilation failure: startup failed: Script1.groovy: 14: unexpected token: } @ line 14, column 36. fieldOptions.put("Proj3","Proj3"); } ^ 1 error


Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2012

Use the exact script provided above . I think there is a extra '}' which you will have to remove.

Suggest an answer

Log in or Sign up to answer