Configuring scripts for generic fields
The operations supported by generic fields are: DEFAULT, GET, SET, INSERT, UPDATE, DELETE, SEARCH and SEQ.
Configuring a read-only field via the Configuration Wizard will only generate the GET, INSERT, UPDATE, DELETE and SEARCH scripts. This is just a starting point, feel free to adjust the scripts according to your needs for the field.
DEFAULT
The DEFAULT script is triggered when creating an issue. It needs to be configured only if you want to initialize the field with a default value. The default value is set only if no other value is manually selected for the field in the Issue Create screen.
Important: you have to refer to the same columns previously defined in the Columns tab. The output of this script has to respect the names, data types and exact order in which the columns are configured.
SQL Example: Let’s assume that for all newly created issues, you want to initialize the Country field with the corresponding values of the table record that has ‘Germany' value in the 'name’ column. You will have to configure the DEFAULT script like this:
SELECT id, code, name, independence, gdp_capita, capital, is_eu FROM countries WHERE name = 'Germany'
GET
The GET script is triggered when the field is displayed in a Jira page. The frequency with which it runs depends on the Refresh type that is configured for the field (General settings for read-only fields | Refresh type ).
Important: the column set as Primary Key is the only indexed parameter that should be used by this script.
SQL Example:
SELECT id, code, name, independence, gdp_capita, capital, is_eu FROM countries WHERE id = {:1}
SET
The SET script is triggered every time the field value is stored in Jira. It is not mandatory to configure it, it's just a helpful instrument in case you need to take an additional step, simultaneous with setting the field’s value.
If the security configured for the field (General settings for generic fields | Security Type ) allows it, users are able to search and set values for the field in Jira. Clicking on the following icon:
will open a dialog in which the SEARCH script will be run, providing it with values present in the dialog’s form that is composed of all the columns marked as searchable in the column list configuration https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15481863/Columns#Searchable.
If a value from the result set is selected, it is stored in Jira and the SET script is triggered.
Important: the column set as Primary Key is the only indexed parameter that should be used by the SET script.
SQL Example: Let’s assume every time you set a value for the field you want to trigger a script that writes in a separate audit table. You will have to configure the SET script like this:
INSERT INTO countries_audit (issue_key, country_id, update_date) VALUES ({issue:key}, {:1}, CURRENT_DATE)
INSERT
The INSERT script is triggered every time the Insert action is completed.
If the security configured for the field (General settings for generic fields | Security Type ) allows it, users are able to insert new rows in the database. Clicking on the following icon:
will render a form with inputs corresponding to the columns in the field configuration. Submitting this form, which can be done either using ‘Insert only’ or ‘Insert & Set’ buttons, will run the INSERT script, providing it with the values filled in the form.
The parameters to be used in the INSERT script should be coded like: {:1}, {:2} etc. which, at runtime, will receive the form value for the field’s column with the specified index.
Important: you have to refer to the same columns previously defined in the Columns tab and make sure you are using the correct index equivalent.
SQL Example: If you want to allow adding new rows to your table, you have to configure the INSERT script like this:
UPDATE
The UPDATE script is triggered every time the Update action is completed.
If the security configured for the field (General settings for generic fields | Security Type ) allows it, users are able to update existing rows in the database. Clicking on the following icon:
will render a form with inputs corresponding to the columns in the field configuration.
Submitting this form will run the UPDATE script, providing it with the values filled in the form.
The parameters to be used in the UPDATE script should be coded like: {:1}, {:2} etc. which, at runtime, will receive the form value for the field’s column with the specified index.
Important: you have to refer to the same columns previously defined in the Columns tab and make sure you are using the correct index equivalent.
SQL Example: If you want to allow updating rows from your table, you have to configure the UPDATE script similar to this:
DELETE
The DELETE script is triggered every time the Delete action is completed.
If the security configured for the field (General settings for generic fields | Security Type ) allows it, users are able to delete existing rows from the database. Clicking on the following icon:
will ask for confirmation to delete the currently selected row. Accepting it will run the DELETE script, providing it with values present in the field.
The parameters to be used in the DELETE script should be coded like: {:1}, {:2} etc. which, at runtime, will receive the value for the field’s column with the specified index.
Important: you have to refer to the same columns previously defined in the Columns tab and make sure you are using the correct index equivalent.
SQL Example: If you want to allow deleting rows from your table, you have to configure the DELETE script similar to this:
SEARCH
The SEARCH script is triggered every time the field has to display the list of possible values for the user to select from.
If the security configured for the field (General settings for generic fields | Security Type ) allows it, users are able to search and set values for the field in Jira. Clicking on the following icon:
will open a dialog in which the SEARCH script will be run, providing it with values present in the dialog.
The parameters to be used in the SEARCH script should be coded like: {:1}, {:2} etc. which, at runtime, will receive the value for the field’s column with the specified index.
Important: you have to refer to the same columns previously defined in the Columns tab. The output of this script has to respect the names, data types and exact order in which the columns are configured.
SQL Example: Let’s assume you want to use as search criteria the code and name of the countries and you want to search for countries having a code or name that contains the values entered in the screen inputs. You will have to configure the SEARCH script like this: