Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Assigning issues via groovy

RandyR October 18, 2012

I'm using Script Runner to assign issues in bulk. With my script it assignes the issue to the user, but in the issue navigator is still shows as Unassigned. What piece am I missing?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.event.type.EventDispatchOption

//Examples, 8 is my subtask issue type id. Will be different for others
updateAssignee("PRJ-1483", "user1")

//Method to do all the work
def updateAssignee(parentId, userName) {
def issue = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserObject(userName)
issue.setAssignee(user)
//Update the issue
ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
RandyR October 18, 2012

I found that all I needed to do was use the IndexManager to have the issue re-index after I updated it.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils

//Examples, 8 is my subtask issue type id. Will be different for others
updateAssignee("PRJ-1485", "user1")

//Method to do all the work
def updateAssignee(parentId, userName) {
def issue = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId)
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserObject(userName)
issue.setAssignee(user)
//Update the issue
ComponentManager.getInstance().getIssueManager().updateIssue(ComponentManager.getInstance().jiraAuthenticationContext?.user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
ComponentManager.getInstance().getIndexManager().reIndex(issue);
}

ConradR
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2013

I'm currently on 5.1.3 and the manual reindex is not necessary (anymore?).

Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2013

Isn't re-index is always needed for that issue once you update it? If you are using in post functions, I guess it is not needed as the it itself includes a re-index.

ConradR
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2013

I'm using it in an EventListener (ISSUE_COMMENTED_ID).

The Javadoc on this method says:

This method will store the provided issue to the JIRA datastore. The issue will be saved and re-indexed.

But maybe that's wrong and my comment event triggered the re-index.

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 18, 2012

Your script is not calling anything that would re-index the issue after your changes.

To test that guess, edit one of the affected issues and then try the issue navigator again. Your edit should trigger a re-index, which should fix the problem with that issue, if I am right.

TAGS
AUG Leaders

Atlassian Community Events