I've seen several answers to this (i stumbled across old answers first so that might affect how i originally coded it).
While this code works, I am curious if i'm over doing some parts and potentially missing some necessary validation.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.permission.ProjectPermission
import com.atlassian.jira.security.plugin.ProjectPermissionKey
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy.autoassign")
def componentAccessor = new ComponentAccessor()
def currentUser = componentAccessor.jiraAuthenticationContext?.getLoggedInUser()
def permissionManager = componentAccessor.getPermissionManager()
log.debug("Auto assign script for issue " + issue.key + " " + issue.assigneeId)
if (issue.assigneeId == null) {
if (permissionManager.hasPermission(new ProjectPermissionKey("ASSIGNABLE_USER"), issue, currentUser)) {
log.debug("Current User= "+currentUser.name+ " - "+ currentUser.id )
def mutableIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey())
mutableIssue.setAssignee(currentUser)
def issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(currentUser, mutableIssue,EventDispatchOption.ISSUE_ASSIGNED, true)
//issue.setAssigneeId(""+currentUser.id)
}
}
Any suggestions would be helpful.
Thanks!
Hello,
The ScriptRunner documentation actually has a basic example of how to do this and how to validate the created issue. In general though, your script looks okay. I'd recommend adding in the validateCreate bit shown in that example just to be safe. :)
Jenna Davis
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.