Cascading Fields with Single Saved Value
To create related fields with Single Saved Value (Supports Select, Autocomplete and Radio) in your SQL custom field plugin, follow these steps:
1. Create the main Field
Create the main field by defining its configuration and adding a query to retrieve relevant data.
For example: this configuration will create a field that displays the actor first names in a select dropdown (change your field type if you want to display data as radio or autocomplete).
After the field creation you should copy the Field ID and keep it in safe place as displaying in the pictures below.
2. Save the value of the main Field
Switch to the Jira view issue, then select your preferred option, and click 'Save' as shown in the picture below.
3. Create the Related Field
After creating and saving the value of the main field, proceed to create the related field.
Define the related field query using the ID of the main field (paste the ID of the main field between '{ }' in the query of the related custom field)
For example:
SELECT last_name FROM actor WHERE first_name = '{SQL_FIELD_14}'
last_name:
is the field to be retrieved from the actor
table.
{SQL_FIELD_14}:
is a placeholder for the first_name
value saved from the first field.
SQL_FIELD_14
is the ID of the main custom field copied in step 1, and it will be replaced with the saved value.
You can refer to the image below:
4. Control the related field based on the main field value
Switch to the Jira view issue.
You'll observe the related field displaying data based on the value of the main field.
Each time you modify and save the value of the main field, the related field will automatically update to reflect the changes.
You can refer to the picture below .
In this query, we will obtain the last names of actors who have the first name 'Penelope'.
Each time you change the first name, the corresponding last name will automatically update accordingly.