Replace Inactive/Missing Assignees on a List of Jira Issues

When migrating data from Jira Server/DC to Jira Cloud, JCMA does not like tickets that have no assignee, or which have tickets with an assignee that has an inactive user status.

This script checks a list of issues, and replaces any that have a missing or inactive assignee.

The script comments should pretty well explain what’s happening with the script. By default it’s set up to check all of the issues in a given project. However, by commenting out one line and uncommenting another, a specific list of issues across any number of projects can be fed to the script.

import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def projectManager = ComponentAccessor.getProjectManager()

final replacementUser = "<username>"
//Define the username that will be used to replace the current assignee

final projName = "<project name>"
//Define the project to be checked

def project = projectManager.getProjectObjByName(projName).id
//Declare a project ID object, using the name of the project

def issues = ComponentAccessor.issueManager.getIssueIdsForProject(project)
//Get all the issues in the project

//final issues = ["<issues>"]
//Uncomment this line and comment out the previous one to feed the script a specific list of issues

issues.each {
  targetIssue ->
    //For each issue in the project

    def user = userManager.getUserByName(replacementUser)
  //Declare a user object, using the name of the replacement user

  def user2 = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
  //Declare another user object, but this time it's the logged-in user running the script

  def issue = issueManager.getIssueObject(targetIssue)
  //Declare an issue object using the current issue ID

  if ((issue.assignee == null) || (issue.assignee.isActive() == false)) {
    //If the assignee of the current ticket is nobody, OR if the assignee has a status of inactive, assign the issue to the replacement user

    def validateAssignResult = issueService.validateAssign(user2, issue.id, user.username)
    //Authenticated user, issue, user to assign to the issue
    //Validate the proposed change

    issueService.assign(user, validateAssignResult)
    //Commit the change
  }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *