Jira automatic assignment based on custom field value

Bryan Karsh
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.
July 22, 2012

Any quick tips? I know the groovy script runner is out there -- but my version doesn't have something for just assigning issues (though I see that some of the scripts, like the fast-track workflow listener, allows users to also assign an issue..)

Basically, when issues are normally created in this particular queue, it automatically gets assigned to the project lead.

I want to maintain this functionality, but I want the issue to be assigned to another user based on a value in a select list custom field.

Help much appreciated. I'm assuming some sort of listener is needed..?

3 answers

1 accepted

0 votes
Answer accepted
John Chin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 30, 2012

Hi Bryan,

Please give a try to this third plugin known as User Picker From Project Role - Issue Alternative Assignee.

Good luck

Bryan Karsh
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.
November 5, 2012

thanks -- looks promising. :)

0 votes
Alexey Paveliev
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.
December 13, 2012

In custom script listener hooked on Create event you can use any of the issue fields, built-in or custom, to do what ever you want:

like assign to hardcoded person based on priority, issue type, etc.

Here an example of complete Listener class file you can modify for your task.

Many people are asking how to start with custom listeners, how to name a class, where to put a file, etc.

I hope this sample will provide some guidance. Just copy it to a file <class name>.groovy and copy to a place where groovy runner can find it (check out this answer)

import java.util.*
import java.sql.Timestamp
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Category
import com.atlassian.crowd.embedded.api.User
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.user.util.UserUtil

//rename your listener class as needed 
class AutoIssueAssignerListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(LoggerService.class)
 
    @Override
    void workflowEvent(IssueEvent event) {
        // only one central way...
        this.customEvent(event)
    }
 

	ComponentManager componentManager = ComponentManager.getInstance()
	
    @Override
    void customEvent(IssueEvent event) {
  
	// set explicit to debug
    log.setLevel(org.apache.log4j.Level.DEBUG) // remove for production
	log.debug "Groovy Service Class name: ${this.getClass().getName()}"
    log.debug "Event: \"${ComponentManager.instance.eventTypeManager.eventTypesMap[event.getEventTypeId()].name}\" fired for ${event.issue}"
 
        // Here you should put any restrictions for this task like
        // only for special issue types or similar
	Issue issue = event.issue
    User user = issue.getAssigneeUser() 
	
	//
	if (issue.isSubTask()) { 
		return
	}
		
	def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
	def cfCategory = customFieldManager.getCustomFieldObjectByName("Category") //use your custom field name here 
	def category = issue.getCustomFieldValue(cfCategory)
	
	def userToReassign = issue.getAssignee()
	UserUtil userUtil = componentManager.getUserUtil()
	
	switch (category) {
	  case "One": 
userToReassign = userUtil.getUserObject("jsmith")
break case "Two":
userToReassign = issue.getProjectObject().getLead()
break } issue.setAssignee(userToReassign) issue.store() } log.debug "Listener ${this.getClass().getName()} completed" } }

It is not tested. Just removed my stuff from working listener and threw in few lines of code that might be relevant to your task

Alexey Paveliev
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.
December 14, 2012

Updated my answer with code sample

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 22, 2012

Just to rule it out - I take it components aren't suitable? (i.e. assign to component lead)

Bryan Karsh
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.
July 22, 2012

Unfortunately, that approach wont work due to how our solution is set up.

Suggest an answer

Log in or Sign up to answer