Dynamic Forms Examples

Create an Issue

The following example shows the use of dynamic form annotations in a script which creates a new issue. A short text annotator is used for Project Key and Summary, select list annotator for Issue Type and Priority, and user picker for User.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.Select
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.parameters.annotation.UserPicker
import com.onresolve.scriptrunner.parameters.annotation.meta.Option

@ShortTextInput(description = "Project key", label = "Project")
String projectKey

@Select(
    description = "The issue type for the new issue",
    label = "Issue type",
    options = [
        @Option(label = "Bug", value = "Bug"),
        @Option(label = "Story", value = "Story")
    ]
)
String issueTypeName

@Select(
    description = "The priority of the new issue",
    label = "Priority",
    options = [
        @Option(label = "High", value = "High"),
        @Option(label = "Low", value = "Low")
    ]
)
String priorityName

@UserPicker(label = "User", description = "User with that user key will be the reporter of the issue")
ApplicationUser user

@ShortTextInput(description = "The summary for the new issue", label = "Summary")
String summary

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def newIssue = Issues.create(projectKey, issueTypeName) {
    setPriority(priorityName)
    // if we cannot find user with the specified key or this was left blank, then set as a reporter the logged in user
    setReporter(user ?: loggedInUser)
    setSummary(summary)
}

"New issue key: $newIssue.key"
Copy

Change Issue Priority

The following example shows the use of dynamic form annotations in a script that changes the priority of an issue. A short text annotator is used for the Issue Key field, select list annotator for Priority, and checkbox annotator for Send Email.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.onresolve.scriptrunner.parameters.annotation.Checkbox
import com.onresolve.scriptrunner.parameters.annotation.Select
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.parameters.annotation.meta.Option

@ShortTextInput(description = "The key of the issue to be updated", label = "Issue Key")
String issueKey

@Select(
    description = "The name of the priority to set",
    label = "Priority",
    options =
        [
            @Option(label = "High", value = "High"),
            @Option(label = "Medium", value = "Medium"),
            @Option(label = "Low", value = "Low")
        ]
)
String priorityName

@Checkbox(description = "Check to send notification email", label = "Send Email")
boolean sendMail

def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)
def availablePriorities = ComponentAccessor.constantsManager.priorities
def priority = availablePriorities.find { it.name == priorityName }
def issueInputParams = issueService.newIssueInputParameters()
issueInputParams.with {
    priorityId = priority.id
}
def updateValidationResult = issueService.validateUpdate(loggedInUser, issue?.id, issueInputParams)
assert updateValidationResult.isValid(): updateValidationResult.errorCollection

def updateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, sendMail)
"Issue priority changed to: $updateResult.issue.priority.name"
Copy

screenshot example of changing priority

On this page