Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Assigning issues via groovy

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

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);
}

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

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.

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

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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you