Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,998
Community Members
 
Community Events
168
Community Groups

User picker style for very long custom field list

I thought it was possible using scripted fields but I might be mistaken. 
We have a list of over 500 system titles and instead of the longest drop down we would like to use the Employee Name Picker logic to allow users to "search" for system title names from the long list. 
Has anyone achieved this using scripted fields ? If so do they use an inline or file script ?

Any additional insight is GREATLY appreciated.
I will continue to look into this while I anxiously await someone with the golden ticket.

2 answers

1 accepted

1 vote
Answer accepted

Thanks very much for the quick and detailed reply @Alejandro Suárez [Tecnofor]

The issue was that I simply did not rename the field in the Behaviour script. 
Once I updated lined 1 of the initialiser to 

getFieldByName("HRIS System Title Scripted").convertToSingleSelect([

Everything worked perfectly !

Thank you !

Glad I hear that! Could you please pick my first comment and mark it as Resolved?

Thank you!

Hi @Keith Shaw, you can achieve this with Behaviours module and a Rest EndPoint.

First of all, you have to create a new text Field (single line). This field is going to replace your select list, but you still have to have your select list customfield to maintain the options available. You can name the text field as you like, even with the same name as the select list.

Second, you have to create a new REST Endpoint. You can achieve this adding new item in the REST Endpoint tab inside the "Add-ons" tab.

I have tested the folloing code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

longList(httpMethod: "GET") { MultivaluedMap queryParams ->

String query = queryParams.getFirst("query") as String
LinkedHashMap map = [:]

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()

CustomField customField = customFieldManager.getCustomFieldObject(10611L)// Replace the ID with your SelectList CustomField
FieldConfig fieldConfig = customField.getRelevantConfig(IssueContext.GLOBAL)
Options totalOptions = optionsManager.getOptions(fieldConfig)
ArrayList<Option> queryOptions = optionsManager.getOptions(fieldConfig).findAll { it.value.toLowerCase().contains(query.toLowerCase()) }

map = [
items : queryOptions.collect { Option option ->
[
value: option.value,
html : option.value.replaceAll(/(?i)$query/) { "<b>${it}</b>" },
label: option.value,
]
},
total : queryOptions.size(),
footer: "Choose a system title... (${queryOptions.size()} of ${totalOptions.size()} shown...)"
]

return Response.ok(new JsonBuilder(map).toString()).build()
}

The only thing you have to replace here is the Select List Field ID and the footer with the text you want.

Third, you have to create a new Behaviour, in the add-ons tab and map it with the projects and issueTypes you want.

In the initialiser Script you have to add the following:

getFieldByName("SelectList Searcher").convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/longList",
query: true,
formatResponse: "general"
]
])

And if you want to avoid the undesirable inline edit of this field, the only thing you have to do is add the field to the same Behaviour.

And finally, don't forget to replace the select list field in the screens you want, with the new text field.

Hope it solve your problem!

Regards.

Thank you very much @Alejandro Suárez [Tecnofor]!
I applied your suggestions but the scripted select box is not searching. 

I assumed the "L" at the end of the CustomFieldObjectID is necessary.

CustomField customField = customFieldManager.getCustomFieldObject(17307L)// Replace the ID with your SelectList CustomField


The Inline script editor shows two warnings one on line29

[Static type checking] - Cannot assign value of type java.util.list <com.atlassian.jira.issue.customfields.option.Option> to variable of type java.util.ArrayList <Option>
@line 20, column 35.

and another at line 35

Ambiguous prototypes for closure. More than one target method matches. Please use explicit argument types. 
@ line 35, column 47.


I see nothing in the execution log so it does not appear to be triggered by entries into the field on the one form it currently resides.

Hi @Keith Shaw,

You can ignore that errors, im getting the same. The first one is because the class is defined as ArrayList<Option> and the console wants an List<Option>. If you dont want to see this error you can change it, but it should work without the change.

I guess you cant avoid the second one, but as I said, you can ignore it.

The only thing I can think about is that the custom field ID you put is not correct.

You have to replace it with the ID of your select list (single pick).

You can test the REST Endpoint searching in your WebBrowser the following address: yourBaseURL>/rest/scriptrunner/latest/custom/longList?query=

(If you want to test further, you can type an option of the select list after "query=")

If you get results then the REST Endpoint is working fine, and the problem is in your Behaviour configuration.

How i configured it:


https://gyazo.com/556c2bd88e75303bb1bc3e5c5710f945

https://gyazo.com/c1895212a6a5fca0b8ebd7d83a74494b

https://gyazo.com/9510910c3a06ae5afc471cca63ee38a0

P.D.: this steps only work in Jira Server, not in Cloud.

Hope it helps!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events