Example Conditions

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 followingScriptRunner Script Condition. Editlength > 0to the minimum number of PDFs required:

    groovy
    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 availabl


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):

    groovy
    user.getProjectRoles(project).map(p => p.name).includes("userrole")

    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 followingScriptRunner Script Condition, replacingusergroupwith the group of users you want to be able to transition the issue (for exampleAdministrators):

    groovy
    user.groups.includes('usergroup')

    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 followingScriptRunner Script Condition. Editlength > 0to the minimum number of sub-tasks required:

    groovy
    issue.subtasks.length > 0

    TheCreatetransition 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. Editsubtask.status.name == 'Done'if you require a different sub-task resolution.

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

    The issue can not transition toDoneuntil all sub-tasks have theDoneresolution.

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.