Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

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

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

Suggest an answer

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

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

247 views 2 1
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