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

Autocomplete Value based on selection - Database Picker fields - Scriptrunner

Hi guys,

I think this is a hard one, but I will try my luck here.

I have 2 database picker fields (Scriptrunner), is there a way to auto-complete a value from the database, based on a selection still from the database?

Example:

I have a MySQL database where I have 2 values in two tables, the value Project_Name and Client_Name. I have created a connexion to this database in ScriptRunner and i have added two fields where i select values in Jira from that database,

Now, is possible somehow when i select Project_Name for example in a field, to autocomplete Client_Name in the other field?

 

Thanks.

1 answer

Hi @Albert,

For your requirement, you could use the ScriptRunner Behaviour.

You can set up a Server-Side Behaviour for the first DB Picker, i.e. Project_Name and use it to update the option selected in the Client_Name DB Picker based on the option chosen in the Project_Name DB Picker field.

Below is an example code for your reference:-

import com.onresolve.scriptrunner.db.DatabaseUtil
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def activeProjects = getFieldById(fieldChanged)
def activeProjectsvalue = activeProjects.value as Long

def dbValues = getFieldByName("Project Components")

def output = []
def result = [:]


DatabaseUtil.withSql('local_db') { sql ->
if(activeProjects.value != null) {
output = sql.rows("select id from sample_components where project_id = ?", activeProjectsvalue)
}
}

output.findAll {
result = it as Map<Integer,String>
}
result.values().findAll {
dbValues.setFormValue(it)
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

If you notice in the code, I am using the local_db as the connection name. Below is a print screen of the example DB Connection that I am using:-

db_connection.png

In this example, I am just using a Local Database configuration, i.e. it will connect to the Database the Jira instance is using.

Below is a print screen of the Behaviour configuration:-

behaviour_configuration.png

 

Below are the sample tables that I am using:-

1) For the Active Projects DB Picker

+--+--------------+
|id|project_name |
+--+--------------+
|1 |Analytics |
|2 |Mobile Apps |
|3 |Web Components|
+--+--------------+

2) For the Project Components DB Picker

+--+--------------+----------+
|id|component_name|project_id|
+--+--------------+----------+
|1 |Statistics |1 |
|2 |UI/UX |2 |
|3 |REST Endpoint |3 |
+--+--------------+----------+

The project_id in the Project Components refers to the id from the Projects table.

Below are a few sample test screens:-

1) The Active Project DB Picker List

image1.png

2) The Project Components DB Picker List

image2.png

3) If the Analytics option is selected from the Active Projects DB Picker, the Statistics option is selected automatically in the Project Components DB Picker as shown in the image below:-

image3.png

4) If the Mobile Apps option is selected from the Active Projects DB Picker, the Statistics option is selected automatically in the Project Components DB Picker as shown in the image below:-

image4.png

5) If the Web Components option is selected from the Active Projects DB Picker, the REST Endpoint option is selected automatically in the Project Components DB Picker as shown in the image below:-

image5.png

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

172 views 6 7
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