Update all issues with last assignee

Hi All,

  • Is there any custom groovy script or function which will allow issues based on a JQL query to modify its assignee field value to its last assignee field value per issue ?
  • Please share your thoughts on this.

 

Regards

Chander Inguva

1 answer

1 accepted

This widget could not be displayed.

Hi All,

         This is the tested and verified code for assigning previous value to assignee field based on a JQL Search.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.changehistory.*;
import com.atlassian.jira.issue.changehistory.ChangeHistory;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.user.ApplicationUsers;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.web.bean.PagerFilter;
 
jqlSearch = "project = <Project_Name> AND issuetype = Story and status = Open and assignee is empty"
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
UserUtil userUtil = ComponentAccessor.getUserUtil();
User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
//Managers
IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
ProjectManager projectManager = ComponentAccessor.getProjectManager();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
MutableIssue mIssue = issueFactory.getIssue();
List<Issue> issues = null;
SearchService.ParseResult parseResult =  searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) 
{
    def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
    issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
    for (Issue issue  : issues)
	{
        List<ChangeItemBean> assigneeChHistory = changeHistoryManager.getChangeItemsForField(issue, "assignee");                             
        if (!assigneeChHistory.isEmpty()) 
		{
		    ChangeItemBean assigneeChItemBean = assigneeChHistory.get(assigneeChHistory.size() - 1);
     	    previousAssignee = assigneeChItemBean.getFrom();
            userManager = (UserManager)  ComponentAccessor.getUserManager()
     		User usera = userManager.getUser(previousAssignee);
            issue.setAssignee(usera);      
            issue.store();
		}
	}
}

Hope this helps.

 

Regards

Chander Inguva

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 4 hours ago in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

18 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you