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() };
}
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.")
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! ✍️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.