The Database Picker scripted field displays database records returned by a pre-configured SQL query from a connected database.
Examples for usage include:
A field to select a customer from your internal customer relationship management database.
A field to select the relevant sales contract from a contracts database, for implementation of a new feature.
From ScriptRunner, navigate to Script Fields. The Script Fields page shows all currently configured scripted fields.
Scripted fields can also be created through Admin→Custom Fields however, they cannot be configured there. For simplicity, navigate to the ScriptRunner Scripted Fields page as outlined above.
Click Create Script Field→Database Picker.
Enter a Field Name. This is the name of the field created.
Add a Field Description.
Enter a Note for the field (optional).
Select a database connection in the Connection field. Configure database connections under the Resources tab.
Two SQL queries are required: a search query and a validation query. Both queries require a unique identifier for the database record being used (such as the primary key).
This identifier should not change. If you are querying a single table, it most likely has a primary key set up.
Often, this is calledIDand will be an auto-incrementing number.
The primary key is stored as a string in a
varcharcolumn in the connected database, allowing ScriptRunner to handle both strings and numbers as keys. However, if the primary key is a number, it must be
castfrom a string to a number in queries.
The Retrieval/Validation SQL query validates the input and retrieves a display value when viewing the issue.
The Search SQL query is used to search the typeahead when creating, editing, or searching issues.
We strongly suggest using the Preview function to check SQL queries.
Check the Multiple checkbox for a multi-select field. Leave unchecked for a single-select field.
Enter a Preview Issue Key and click Preview. The preview runs the Retrieval/Validation SQL and Search SQL queries for the issue provided. Use the preview to check for errors in your queries.
After confirming the queries work as expected, click Add.