How to set default value in searchable list using scriptrunner?

Hello,

 

Could somebody tell me how can I select the first option from the retrived values and set this value to the searchable list (this list is used as a picker for selecting issues)? This is the code that I am using, the below line is setting the value, althoug on save this value is lost (the value that I am passing seems to be not poicked up correctly)

getFieldByName(fieldName).setFieldOptions(["1":"${issue.summary}"])

Could somebody help me with this?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

log.setLevel(org.apache.log4j.Level.DEBUG)

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("project = currentProject() AND issuetype = 'Story' AND Active='Yes' ")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

def nameFieldList = ["Name #1","Name #2","Name #3", "Name #4", "Name #5", "Name #6"];

results.getIssues().each {documentIssue ->
    log.debug(documentIssue.key)

    def issue = issueManager.getIssueObject(documentIssue.id)

    log.debug(issue.summary)

for (fieldName in nameFieldList )
{  
    getFieldByName(fieldName).setFieldOptions(["1":"${issue.summary}"])
    getFieldByName(fieldName).convertToSingleSelect([ 
    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 = currentProject() AND issuetype = 'Story' AND Active='Yes' ORDER BY key ASC",
            label       : "Pick Story issue", 
            showSubTasks: false, 
        ],
        formatResponse: "issue" 
    ],
    css: "max-width: 500px; width: 500px", 
])
}
}

1 answer

0 vote

Don't think this is possible right now: https://productsupport.adaptavist.com/browse/SRJIRA-2159

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Amir Kazemi
Posted 3 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

17 views 0 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you