Forums

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

How to assign an issue via Script Listener

Michael Schultz March 11, 2019 edited

I have this Listener (below). What I want to happen:

When the issue type is set as 'Enhancement Request' by a specified author, assign the issue to another specified user (user).

If the event author is not the user I've specified, ignore this auto-assignment.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Category;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue


def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.INFO)

Issue issue = event.issue as MutableIssue
def issueObject = issue.getKey()
def author = event.getUser().getDisplayName()

if( ["Enhancement Request"].contains(issue.issueType.name) && author == {string username})
{ log.info 'Issue Type is Enhancement Request.'
def userManager = ComponentAccessor.getUserManager()
def user = ComponentAccessor.getUserManager().getUserByKey({string username})
def admin = userManager.getUserByName({string username})


issue.setAssigneeId(user)
return "Author = " + { log.info author.toString() };
return "Assignee = " + { log.info user.toString() };
}

@Adaptavist Supp 

1 answer

1 accepted

0 votes
Answer accepted
Michael Schultz March 13, 2019 edited

For those of you wondering, I retooled the script and was able to solve it. Here it is:

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager

UserManager userManager = ComponentAccessor.getUserManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()

def issue = event.getIssue() as MutableIssue
def author = event.getUser().name.toString()
final List<String> projTeam = ['user1', 'user2', 'user3', 'user4']

ApplicationUser assignToUser = userManager.getUserByKey('user5')

if (["Enhancement Request"].contains(issue.issueType.name) && author in projTeam) {
issue.setAssignee(assignToUser)
issueManager.updateIssue(assignToUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
log.info(author + " changed ticket to Enchancement Request.")
}
else
log.info("Non-projTeam user switched issue to Enhancement Request.")

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events