Built-in Workflow Actions
ScriptRunner for Jira Cloud has many built-in workflow actions; each of these is outlined below.
Add/remove to/from sprint
Using this function, you can either add a work item to an active sprint or remove it from its current sprint after a transition.
For example, on the Start Progress transition, you can apply this workflow action to automatically add the transitioned work item to the current sprint. Although this does not follow scrum methodology, there may be times when the team has finished all work in a sprint, and this workflow action automatically adds work items to the sprint.
See the available Script Context for Condition and Additional Code fields in the Script Context section.
Assign Work Item
Assign Work Item takes the item and assigns it to the last assignee with a specified role or from a user group. You must specify either a space role or a user group. If both are defined, the space role is used, and the user group is skipped.
For example, a developer finishes working on a work item and marks it as Ready to Test. After the work item is transitioned, it is automatically assigned to a tester. The tester rejects the work item, and it returns to the development team. The last user assigned to the development role is reassigned to the work item. The dev can then fix the work item and transition it back to the QA team. When they do, the work item is reassigned to the same tester (the last user in the tester role).
Clone Work Item
Work Item Description: When cloning a work item with attachments in the rich text field, you may encounter an error if you have enabledAtlassian's new transition experience. Read more in our Breaking Changes documentation. For example:
2025-03-14 18:34:49.554 WARN - POST request to /rest/api/3/issue returned an error code: status: 400 - Bad Requestbody: {errorMessages=[], errors={description=We don't recognise the format of a file you added or the data in it. Remove and try again.}} This is a known issue related to an Atlassian bug (JRACLOUD-93305). Below is a workaround to mitigate its impact by clearing the field or replacing the content manually.
Workaround: We recommend checking the field value's format type (Map or String) before clearing or setting it. This ensures that both sets of users, those who have/do not have the new transition experience enabled, are supported. For example, we can use the Description field as shown below:
def originalDescription = issue.fields.descriptionif (originalDescription instanceof Map) { // New experience (ADF) issueInput.fields.description = new groovy.json.JsonSlurper().parseText(""" Your ADF format """)} else if (originalDescription instanceof String) { // Old experience (plain text) issueInput.fields.description = "Your plain text value"}We recommend this approach as necessary due to the following reasons:
For users of the new transition experience, API v3 (
/rest/api/3/issue) expects the description in ADF (Atlassian Document Format) and will fail if a plain string is passed.For users of the old transition experience, API v2 (
/rest/api/2/issue) expects the description in plain text and will fail if ADF is passed.
Rather than leaving blank content, you can include custom content using Atlassian's ADF Builder Playground to enter values in the editor and generate content in ADF format. Since it outputs JSON, you can directly parse it in the console, similar to this Scripted Fields example:
issueInput.fields.description = new groovy.json.JsonSlurper().parseText("""Your ADF""")Clone Work Item creates a clone of a selected work item and optionally links the two items. Specify the target space, work type, link type, and link direction (between the source work item and the clone). For example, you have a ticket for a potential new hire. When this ticket transitions to Hired you want to automatically clone the work item to the IT board so the team can set up their login details.
It is possible to override issueInput with a new structure by setting issueInput from additional code; however, this is not recommended.
See the available Script Context for Condition and Additional Code fields in the Script Context section.
Supported field types
The Clone Work Item function only copies Jira system fields and any custom fields that have the following types:
- Checkbox
- Date picker
- Date time picker
- Labels
- Number field
- Radio button
- Select list
- Multi-select list
- Single text field
- Multi-row text field
- URL field
- User picker
- Group picker
- Multi-select group picker
- Space picker
- Multi-select user picker
- Version picker
- Multi-select version picker
Create sub-task
Create a sub-task for the work item being transitioned. Specify the sub-task type and title, along with executing additional code. Additional code has issueInput bound as the structure that is used in the post to /rest/api/2/issue to create the sub-task. Overriding issueInput is possible by setting issueInput as part of the script.
For example, a ticket needs to be checked by several departments before it is considered Done. Using this workflow action, you can automatically create sub-tasks for these departments when a ticket is created.
Create sub-task example
Here is the code we run under the hood in the provided function, modified so you can run it in the script console:
// Here we specify and retrieve the details of the parent work item
// If you copied this code into a Perform actions rule or an item-related Script Listener you could remove
// the first 5 lines of code as an work item variable would already be available to your script
def parentKey = 'DEMO-1'
def issueResp = get("/rest/api/2/issue/${parentKey}")
.asObject(Map)
assert issueResp.status == 200
def issue = issueResp.body as Map
// We retrieve all issue types
def typeResp = get('/rest/api/2/issuetype')
.asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>
// Here we set the basic subtask work item details
def summary = "Subtask summary"
def issueType = "Sub-task"
def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
assert issueTypeId : "No subtasks issue type found called '${issueType}'"
def createDoc = [
fields: [
project: (issue.fields as Map).project,
issuetype: [
id: issueTypeId
],
parent: [
id: issue.id
],
summary: summary
]
]
// Now we create the subtask
def resp = post("/rest/api/2/issue")
.header("Content-Type", "application/json")
.body(createDoc)
.asObject(Map)
def subtask = resp.body
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
subtaskFast-track transition work item
Use Fast-track Transition Work Item to immediately transition an item if the provided condition is true. Transitions are specified by name and must be valid for the work item that is to be transitioned.
For example, all work items that have the item priority Major should be escalated to get additional sign-off after creation.
See the available Script Context for Condition and Additional Code fields in the Script Context section.
Modify work item
Update the work item, or perform any action on the item after a transition.
issueInput to null. Cancelling an update allows you to use this workflow action in a similar way to a script listener.Running as the add-on user adds overrideScreenSecurity=true as a query parameter to allow editing fields that are not on the screen.
Run script
Run arbitrary code after a transition.
Send notification
Generate an email notification to send to a number of users and/or groups, including Watchers, Voters, the Reporter, and Assignee.
The following is an example of constructing an email from the work item details.
Use the following in the Condition field to specify that the work item must have an assignee
issue.fields.assignee != nullEnter the following into the Message field to retrieve the value for the 'TextFieldB' custom field and construct the notification body:
def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>
defcustomFieldId = fields.find { it.name == 'TextFieldB' }.id as String
defcustomFieldValue = (issue.fields[customFieldId] as Map)?.value
"""Dear ${issue.fields.assignee?.displayName},
The ${issue.fields.issuetype.name} ${issue.key} with priority ${issue.fields.priority?.name} has been assigned to you.
Description: ${issue.fields.description}
Custom field value: ${customFieldValue}
Regards,
${issue.fields.reporter?.displayName}"""Line 5: Retrieve the custom field ID for the 'TextFieldB' custom field.
Transition parent work item
Transition the parent work item of a sub-task.
The specified transition is performed on the parent of the sub-task when a condition is met. As with Fast-Track Transition Item, the transition name is provided and not validated.