ScriptRunner for Jira Cloud Logo

Getting Started

JIRA Extension Points

Releases

A script condition is a workflow condition that allows you to extend the functionality you find in a basic Jira workflow condition. A condition checks to make sure that a requirement is met before you can transition an issue. If the script returns false the transition button is not available for an issue until the condition is met.

There are several ways to enhance your workflow using script conditions, including:

ScriptRunner for Jira Cloud provides workflow conditions using the Jira Expression Framework. It is not possible to use the REST API.

Tip
Navigate to Context Variables to see the variables provided by this framework that can be used to create expressions. Click the variables to view the properties that can be called.

Create Condition

  1. Select the transition you wish to add the condition to.

  2. Click Conditions→Add Condition.

  3. Select the ScriptRunner Script option then Add.

  4. Enter the Name of ScriptRunner Script Condition.

  5. In the ScriptRunner Script Condition field, enter the script condition expression. This script condition must be written as a Jira expression.

Tip
For help navigating to ScriptRunner workflow functions, follow the steps to navigate to workflow functions.

Edit Condition

  1. Select the transition the condition is on.

  2. Click Conditions. A list of all conditions on the selected transition is shown.

  3. To edit an existing condition, click the Pencil.

  4. Edit the condition and click Update.

Examples

Require Attachments

For example, you want a PDF of the contract agreement attached to an issue before work can begin, so developers know what was agreed with the client. This script ensures at least one PDF file is attached before the issue can be transitioned.

  1. Select the Start Progress transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Require PDF Attachments.

  5. Insert the following ScriptRunner Script Condition. Edit length > 0 to the minimum number of PDFs required:

      issue.attachments.filter(attachment => attachment.mimeType == 'application/pdf').length > 0

    This condition now ensures there must be at least one PDF file attached to the issue for the transition option to be available.

Restrict Transition Permissions

As a team lead, you want to restrict the transition of issues to specific groups or roles. This condition only shows transition options to users belonging to the groups or roles specified.

Restrict to Role

  1. Select the Approved transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Restrict Approval to Developers Role.

  5. Insert the following ScriptRunner Script Condition, replacing userrole with the user role you want to be able to transition the issue (for example Developers):

        user.getProjectRoles(project).map(p => p.name).includes("userrole")
    Tip
    Roles apply to projects only, whereas user groups are global. See the Atlassian documentation for information on managing project roles.

    This condition ensures only users in the user role(s) listed can transition an issue.

Restrict to Groups

  1. Select the Approved transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Restrict Approval to Jira Administrators Group.

  5. Insert the following ScriptRunner Script Condition, replacing usergroup with the group of users you want to be able to transition the issue (for example Administrators):

        user.groups.includes('usergroup')
    Tip
    See the Atlassian documentation for information on viewing, creating, or deleting groups.

    This condition ensures only users in the user group(s) listed can transition an issue.

Require Sub-tasks

As a project manager, you want developers to add sub-tasks to issues so you can see the steps required to complete an issue. You want to stop the transition of an issue if it has no sub-tasks. This script only shows the transition option if the issue has at least one sub-task.

  1. Select the Create transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Require Sub-tasks.

  5. Insert the following ScriptRunner Script Condition. Edit length > 0 to the minimum number of sub-tasks required:

      issue.subtasks.length > 0

    The Create transition option is not available until at least one sub-task is created for the issue.

Sub-tasks Must be Done

You want to enforce that Done means all sub-tasks are completed. Disallow the transition of an issue when there are outstanding sub-tasks. This script only shows the transition option when all sub-tasks have the Done resolution.

  1. Select the Done transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Require Sub-tasks are Done.

  5. Insert the following ScriptRunner Script Condition. Edit subtask.status.name == 'Done' if you require a different sub-task resolution.

      issue.subtasks.filter(subtask => subtask.status.name == 'Done').length == issue.subtasks.length

    The issue can not transition to Done until all sub-tasks have the Done resolution.

Sub-tasks Must have Assignee

You want to make sure sub-tasks and their parent issue remain aligned and all sub-tasks have developers assigned. Disallow the transition of an issue when sub-tasks do not have assignees. This script only shows the transition option when all sub-tasks have assignees.

  1. Select the Start Progress transition.

  2. Click Conditions→Add Condition.

  3. Select ScriptRunner Script and click Add.

  4. Add a description of the condition in Name of ScriptRunner Script Condition for example, Require Sub-tasks have Assignees.

  5. Insert the following ScriptRunner Script Condition.

      issue.subtasks.filter(subtask => subtask.assignee != null).length == issue.subtasks.length

    The issue can not transition to In Progress until all sub-tasks have assignees.