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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I update a text field converted to select list by ScriptRunner Behaviours script?

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

2 answers

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

144 views 1 12
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you