Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update assignee on an issue at creation via scriptrunner

Mark Lang
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.
March 7, 2018

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!

1 answer

0 votes
Jenna Davis
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.
March 9, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events