Dynamic Forms
Use the Dynamic Forms feature to simplify the process of adding variables to your ScriptRunner Groovy scripts
With Dynamic Forms, you can annotate your variables in a script so they appear as selectable form fields. You can then save that script as a file to be shared with multiple users, allowing one script to be used for various use cases.
Why is the Dynamic Forms feature useful?
Inline scripts are often copied and pasted, with minor changes made for different use cases, which requires maintenance for each script usage. Using Dynamic Forms, you can create flexible scripts with annotated variables that can be stored as files, reducing maintenance requirements while allowing for script customization. Additionally, these annotations allow variable values within a script to be changed easily by those with limited code familiarity.
Where can you use the Dynamic Forms feature?
Available dynamic form field types
The following dynamic form field types are available:
| Name | Description | Target Type |
|---|---|---|
| Short text | Field allowing a short text input | String |
| Number | Feud allowing an integer | Integer |
| Select list | Single-select list field Custom select list Tip: Custom select list If you cannot find an annotation that is suitable for your purpose, you can use | String |
| Checkbox | A checkbox field | Boolean |
| Space picker | Field allowing space selection | com.atlassian.confluence.spaces.Space |
| User picker | Field allowing user selection | com.atlassian.confluence.User |
Creating a dynamic form
The steps below describe how we expect most users to use the Dynamic Forms feature. This feature can be used in whatever way you find most useful.
- Create the dynamic form in the Script Console to make sure it works as expected.
- Save the dynamic form as a file.
- Use the saved file in a Job, Listener or other ScriptRunner feature.
The above steps are detailed below.
This is useful because instead of hardcoding the query variable, you can use the dynamic form annotation, meaning the query can be changed without needing to re-write the script.
Transforming an existing inline script into a dynamic form
To enable sharing of annotated scripts, all inline scripts must be saved as files.
Annotations
Short text
Add a short text field to a script
import com.onresolve.scriptrunner.parameters.annotation.*
@ShortTextInput(label = "Page name", description = "Enter a name for your page")
String pageNameTextInputNumber
Add a number field to a script
import com.onresolve.scriptrunner.parameters.annotation.NumberInput
@NumberInput(label = "Number of child pages", description = "How many child pages to create") Integer numberOfChildPagesSelect list
Add a single-select list with configurable options
import com.onresolve.scriptrunner.parameters.annotation.*
import com.onresolve.scriptrunner.parameters.annotation.meta.*
@Select(
label = "Color",
description = "Select color",
options = [
@Option(label = "Green", value = "green"),
@Option(label = "Blue", value = "blue"),
]
)
String valueUsing optionsGenerator in a select list
If you cannot find an annotation that is suitable for your purpose, you can provide an optionsGenerator closure when using @Select to generate a list of custom options. For example:
import com.onresolve.scriptrunner.parameters.annotation.Select
@Select(
label = "Color",
description = "Select color",
optionsGenerator = {
[
['yellow', 'Yellow'],
['red', 'Red'],
]
}
)
String value- The first element must be the option value (that is, what is injected into your variable).
- The second element must be the display value.
The closure code must be completely self-contained, apart from import declarations. Therefore, you cannot use variables or methods declared outside the closure.
We recommend you keep the contents of these closures short and simple.
The following is a Jira example, using optionsGenerator, that lists all projects in a specific project category:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.parameters.annotation.Select
@Select(
label = "Project",
description = "Select the Space project",
optionsGenerator = {
def projectManager = ComponentAccessor.projectManager
def category = projectManager.getProjectCategoryObjectByName('Space Projects')
projectManager.getProjectObjectsFromProjectCategory(category.id).collect { project ->
[project.key, project.name]
}
}
)
String valueCheckbox
Add a checkbox to the script
import com.onresolve.scriptrunner.parameters.annotation.*
@Checkbox(label = "Clone space", description = "Select the checkbox to clone a space")
Boolean spaceShouldBeClonedUser picker
Add a user picker into your script
import com.atlassian.user.User
import com.onresolve.scriptrunner.parameters.annotation.*
@UserPicker(label = "User", description = "User for test")
User userAdd a user multi-picker
import com.atlassian.user.User
import com.onresolve.scriptrunner.parameters.annotation.*
@UserPicker(label = "Users", description = "Users for test", multiple = true)
List<User> usersSpace picker
Add a space picker to your script
import com.atlassian.confluence.spaces.Space
import com.onresolve.scriptrunner.parameters.annotation.SpacePicker
@SpacePicker(label = "Space", description = "Pick a space")
Space spaceAdd a space multi-picker to your script
import com.atlassian.confluence.spaces.Space
import com.onresolve.scriptrunner.parameters.annotation.SpacePicker
@SpacePicker(label = "Spaces", description = "Pick spaces", multiple = true)
List<Space> spaces