You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Automatically Assign an Issue based on the Modulus Value of the Issue Key

Overview

This console script assigns issues to the users according to the modulus value of the issue's key.

Example

I work as a Project Manager. When I create an issue, I want to automatically assign it to a user based on the modulus value of the issue key. This ensures that all issues have a user assigned when the issue is created. I can adjust the modulus value calculator to balance workloads between users.

Requirements

  • Jira Jira (8.5 - 8.22)
  • ScriptRunner for Jira ScriptRunner for Jira (6.45.0)
    
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue def issueManager = ComponentAccessor.issueManager def projectManager = ComponentAccessor.projectManager def userManager = ComponentAccessor.userManager //Specify Project Key def project = projectManager.getProjectByCurrentKey('') //Specify User's Name def user1Id = '' def user2Id = '' def user3Id = '' def issues = issueManager.getIssueObjects(issueManager.getIssueIdsForProject(project.id)) issues.sort().each { def issue = it as MutableIssue def user1 = userManager.getUserByName(user1Id) def user2 = userManager.getUserByName(user2Id) def user3 = userManager.getUserByName(user3Id) def filter = issue.key.replace("${project.key}-", '') as Integer if ( filter % 10 == 0 ) { issue.setAssignee(user1) } else if ( filter % 2 == 0 || filter % 3 == 0 ) { issue.setAssignee(user2) } else { issue.setAssignee(user3) } issueManager.updateIssue(issue.assignee, issue, EventDispatchOption.DO_NOT_DISPATCH, false) }
Discovered an issue? Report it here

Suggested for you