Hello,
I have a text field that I am converting to a select list using the tutorial from https://scriptrunner.adaptavist.com/4.3.5/jira/behaviours-conversions.html. The field worked great as an initialiser function, but I'd like to use the field as a server-side script for a user picker field. When the user selects a different user with the user picker, the select list shows all issues where that user is the reporter. I tried to do this following the tutorial under 'Dynamically Changing the Picker Query'. The script works, but each time the user picker field is updated a new drop down box appears above the previous one. Is there a way to remove the old drop down box?
Here is the code I am working with:
//Server-side script for user picker field
def traveler = getFieldById(getFieldChanged())
def linkedIssuesField = getFieldByName("Linked issue selection")
if(traveler){
linkedIssuesField.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner-jira/latest/issue/picker",
query : true,
data : [
currentJql : "Reporter in (${traveler.getValue()}) ORDER BY key ASC",
label : "Which trip is this update for?",
],
formatResponse: "issue"
],
css : "max-width: 500px; width: 500px",
])
}
else {
// selected project was null - disable control
linkedIssuesField.convertToShortText()
linkedIssuesField.setReadOnly(true).setDescription("Please select a reporter before entering the issue")
}
//Server-side script for the issue picker field
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def selectedIssueField = getFieldById(getFieldChanged())
def selectedIssue = selectedIssueField.value as String
log.debug("selectedIssue changed: ${selectedIssue}")
def selectedProject = getFieldByName("Linked issue selection").value
if (selectedIssue && selectedProject) {
def jqlQueryBuilder = JqlQueryBuilder.newBuilder()
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def query = jqlQueryBuilder.where().project(selectedProject.id).and().issue(selectedIssue).buildQuery()
if (searchService.searchCount(user, query) == 1) {
selectedIssueField.clearError()
}
else {
selectedIssueField.setError("Issue not found in the selected project")
}
}
Thank you
Any news an that?
I have the same problem using a Database Picker to get all organisational units from the database. In a SR behaviour (on change) I get the selected OU and fetch all OU members from database using the convertToSingleSelect. Each time the OU is changed a new Select is appended into the DOM - I just would need the content of the dependent selectbox beeing updated.
By the way in version 5.7.1 there is still no possibility in dynamically loading a selectbox, there is only the option to filter out some preconfigured (select)options but not append new ones?
Regards
Hi @Mick Lovell
I am trying to do quite similar to what you did. I am trying to populate the list with values from the database into 2nd element the one which we are converting to select a single value instead of calling results for issues.
Any idea?
Thanks
Ankini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.