Use the Autocomplete editor and $userInput
Problem
If you're experiencing performance problems in the input screens (create/edit/transition screens), we recommend using the Autocomplete editor with the $userInput variable in order to filter the results returned by the datasource.
$userInput variable is only available in this Autocomplete editor, as it's the only one that allows users to type characters into the field to look for specific values.
Useful variables and functions
To complete this use case, 3 variables should be used:
$userInput: This variable contains what a user types into the field, and is used to filter results according to what the user is looking for.
$currentCustomfieldValue: This variable contains the value currently selected in the field. It corresponds to the key you have set in your Connect field and is stored in Jira.
$query.abort(): This function cancels the query execution. When executed, the datasource is not contacted.
Solution
Imagine that you have a Elements Connect field based on the following SQL query:
Edit view configuration
This is how the Edit view query should look:
#if($userInput.length() > 0)
SELECT user_id, username
FROM users
WHERE username like '$userInput'
#elseif($currentCustomfieldValue.size() > 0)
SELECT user_id, username
FROM users
WHERE user_id = $currentCustomfieldValue
#else
$query.abort()
#end
Here's how this query works:
If the user has typed characters into the field, then the 1st condition is passed and the SQL query is filtered based on $userInput (depending on the data displayed in the template).
If the user hasn't typed anything yet, but if a value is currently selected in the field, then the 2nd condition is passed. In this case, the query is executed based on $currentCustomfieldValue (depending on the key stored in Jira).
If $userInput and $currentCustomfieldValue are empty, this means that the user hasn't typed anything into the field and no value is currently selected. It is therefore pointless to contact the datasource and we execute $query.abort() to cancel the query execution.
Display view configuration
The $userInput variable can only be used on input screens (create/edit/transition screens) to allow users to enter characters, and is therefore not supported on display screens (such as the issue view, dashboards, etc.):
So you need to configure a custom Display view query, as follows:
Go to the Display view tab
Check the box called "Configure a specific query"
Write the following query:
CODE#if($currentCustomfieldValue.size() > 0) SELECT user_id, username FROM users WHERE user_id = $currentCustomfieldValue #else $query.abort() #end