Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

create select list from JQL

NogaE September 15, 2016

Hi guys,

 

I'm looking for a way to create a select list using the values of JQL search.

The JQL is different between issues and will be based on the value of another field of the issue.

I'm looking for a way to convert a scripted field to select list , plugin who does it or any other idea.

 

Will appreciate any help.

Thanks,

Noga.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
JamieA
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.
September 15, 2016

For a ScriptRunner solution, that is what select list conversions are for...

NogaE September 17, 2016

Im running a server side script on a select list field that will his value is important for the JQL. 

The problem that if I change the value in the edit screen, the converted field is not being updated. Only after re-enter the edit screen in the second time.

This is my script:

import com.atlassian.jira.project.version.Version
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
 
@BaseScript FieldBehaviours fieldBehaviours
 
def formField = getFieldById(getFieldChanged())
 
def project = formField.getValue()

def jqlSearchField = getFieldByName("text field 2")
if (project) {
    jqlSearchField.setReadOnly(false).setDescription("Select an issue in the ${project} project")
    jqlSearchField.convertToSingleSelect([
        ajaxOptions: [
            url           : getBaseUrl() + "/rest/scriptrunner-jira/latest/issue/picker",
            query         : true,
            data          : [
                currentJql  : "project = ${project} ORDER BY key ASC", 
                label       : "Results for issues in ${project} project",
            ],
            formatResponse: "issue"
        ],
        css        : "max-width: 500px; width: 500px",
    ])
}
else {
    jqlSearchField.setReadOnly(true)
}

 

Thanks,

Noga.

JamieA
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.
September 19, 2016

what version of ScriptRunner?

NogaE September 25, 2016

4.3.6

JamieA
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.
September 26, 2016

So when you change the project field the search results don't change?

Have you put this script on the project custom field (maybe you put it on the initialiser, which only runs at form load)?

NogaE September 26, 2016

Yes, it doesn't change immediately, only after I click "done" and re-enter edit screen.

I've tried using the following script as an initialiser and now don't get results at all.

import com.atlassian.jira.project.version.Version
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
 
@BaseScript FieldBehaviours fieldBehaviours
 
def formField = getFieldById("customfield_10703")
 
def project = formField.getValue()

getFieldByName("text field").convertToMultiSelect([ 
    ajaxOptions: [
        url : getBaseUrl() + "/rest/scriptrunner-jira/latest/issue/picker",
        query: true, // keep going back to the sever for each keystroke
        // this information is passed to the server with each keystroke
        data: [
            currentJql  : "project = ${project} ORDER BY key ASC", 
            label       : "Test Noga Pick high priority issue in Support project", 
            showSubTasks: false, 
            // specify maximum number of issues to display, defaults to 10
            // max       : 5,
        ],
        formatResponse: "issue" 
    ],
    css: "max-width: 500px; width: 500px", 
])
JamieA
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.
September 26, 2016

As I said, don't use an initialiser, you need to add this to the customfield_10703 field

NogaE September 26, 2016

It was on customfield_10703 and didn't changed when the value was changed.

Jonny Carter
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.
September 28, 2016

I believe what Jamie means is that your script needs to be associated with the custom field in the behaviour's configuration, rather than being in an initialiser function. For example, in the screenshot below, the script is associated with the Assignee field, and no initialiser is defined.

Screen Shot 2016-09-28 at 10.32.47 AM.png

Specifying the custom field with getFieldById("customfield_10703") still won't work if it's done in an initialiser function.

TAGS
AUG Leaders

Atlassian Community Events