Dynamic Forms
Use the Dynamic Forms feature to simplify the process of adding variables to your ScriptRunner Groovy scripts. Dynamic Forms allows you to create complex scripts with flexible variables that can be shared with multiple users, allowing one script to be used for various use cases.
Inline scripts are often copied and pasted, with minor changes made for different use cases. This approach requires maintenance for each usage of the script. Using Dynamic Forms, create flexible scripts with annotated variables that can be stored as files, reducing maintenance requirements while allowing for script customization.
Annotate your variables to have them appear as form fields when a user edits a script. These annotations allow variable values within a script to be changed easily by those with limited code familiarity.
Dynamic forms annotations are available anywhere you can enter code in ScriptRunner, including the Script Console, Conditions, Validators, Post Functions, Behaviours, and many more.
For example, as a power user, you have created a script to delete issues within a project with a specific assignee. This script is used across multiple locations, varying by one variable (User) for each use case. Instead of hardcoding the User variable, you can now use a dynamic form annotation, meaning the user can be changed without needing to re-write the script. As well as being able to edit the script quickly, you can maintain the code in one centralized location. The dynamic form annotation shows the User variable as a form field.
The above example uses the following code:
The following dynamic form field types are available:
User Picker | Field allowing user selection. | |
Field Picker | Field to select any system or custom field. | |
Short Text | Field allowing a short text input. | String |
Select List | Single-select list field. | String |
Checkbox | A checkbox field. | Boolean |
Project Picker | Field allowing project selection. | |
Priority Picker | Field allowing priority selection. | com.atlassian.jira.issue.priority.Priority |
Issue Type Picker | Field allowing issue type selection. | com.atlassian.jira.issue.issuetype.IssueType |
Issue Link Type Picker | Field allowing issue link type selection. | com.atlassian.jira.issue.link.IssueLinkType |
Project Role Picker | Field allowing project role selection. | com.atlassian.jira.security.roles.ProjectRole |
Group Picker | Field allowing group selection. | com.atlassian.crowd.embedded.api.Group |
Saved Filter Picker | Field allowing saved filter selection. | com.atlassian.jira.issue.search.SearchRequest |
Issue Status Picker | Field allowing status selection. | com.atlassian.jira.issue.status.Status |
We are in the process of adding more dynamic form field types.
Create a Dynamic Form
Click the Cog in the top ribbon, and open the Add-ons page.
Select Script Console under ScriptRunner.
Write your new script in the Script field, annotating the variables you want users to provide (see the Examples section below). Annotating variables allows them to be edited depending on requirements when running the script. These variables show as editable fields above the Script Console.
Transforming an Existing Inline Script
To enable sharing of annotated scripts, all inline scripts must be saved as files.
Navigate to your existing inline script, and add in required annotations.
Copy the script.
Use the Script Editor to open your Scripts Root folder.
Select the folder in which you want to save the script, and click the Create New File icon.
Enter a file name in the Add New Groovy File/Add New Groovy Folder window.
Click Add.
Paste your inline script into the file, and click Save. This script is now available as a file and can be shared with multiple Jira users on the same instance.
Annotations
User Picker
Add a user picker field into your script.
User multi-pickers are also supported.
Field Picker
Add a field picker into your script. The field picker lets you pick from any fields (system or custom).
Field multi-pickers are also supported.
Short Text
Add a short text field to a script.
Select List
Add a single-select list with configurable options.
Multi-select lists are also supported.
Checkbox
Add a checkbox to a script.
Project Picker
Add a project picker to a script.
Project multi-pickers are also supported.
Priority Picker
Add a priority picker to a script.
Priority multi-pickers are also supported.
Issue Type Picker
Add an issue type picker to a script.
Issue type multi-pickers are also supported.
Issue Link Type Picker
Add an issue link type picker to a script.
Issue link type multi-pickers are also supported.
Project Role Picker
Add a project role picker to a script.
Project role multi pickers are also supported.
Group Picker
Add a group Picker to a script.
Group multi-pickers are also supported.
Saved Filter Picker
Add a saved filter to a script.
Saved filter multi-pickers are also supported.
Issue Status Picker
Add a status to a script.
Issue status multi pickers are also supported.
Custom Field Picker
Add a custom field picker to a script.
Custom field multi-pickers are also supported.
Resolution Picker
Add a resolution to a script.
Resolution multi-pickers are also supported.
Version Picker
Add a version to a script.
Version multi-pickers are also supported.
Component Picker
Add a component to a script.
Component multi-pickers are also supported.