Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,828
Community Members
 
Community Events
165
Community Groups

HOw to auto assign the issue based on select list custom field values?

I have select list Custom field "Po Region" , it has 2 options "Bengaluru" and "Mumbai" if bengaluru option selected it has to assign to "user A" else Mumbai selected assign to "user B"

I have worked with script runner 

1) script Listener

2) post function 

Both didn't work 

I have this following code 

 

import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.user.util.UserUtil
import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

log.debug "Starting postfunction..."
if (issue.isSubTask()) {
log.debug "Issue is subtask, leaving."
return
}

def customFieldManager = componentManager.getCustomFieldManager()
def cfCategory = customFieldManager.getCustomFieldObjectByName("Po Region")
log.debug "Found customfield ${cfCategory}."
def category = (issue?.getCustomFieldValue(cfCategory) as Option)?.value
log.debug "Got category ${category}."

def userToReassign = issue.getAssignee()
log.debug "Got assignee ${userToReassign}."
UserUtil userUtil = componentManager.getUserUtil()

switch (category) {
case "Bengaluru":
log.debug "Getting user for Desktop category."
userToReassign = userUtil.getUserObject("shivprasad.hattaraki")
break
case "Mumbai":
log.debug "Getting user for Network category."
userToReassign = userUtil.getUserObject("avinash.deshpande")
break
}
log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)
issue.store()

 

It doesn't work , plz help me on this problem.

 

This is log details

 

Time (on server): Thu Jul 19 2018 10:41:05 GMT+0530 (India Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2018-07-19 10:41:05,815 DEBUG [workflow.ScriptWorkflowFunction]: Starting postfunction...
2018-07-19 10:41:05,828 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-07-19 10:41:05,828 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: componentManager for class: Script950
	at Script950.run(Script950.groovy:13)

 

1 answer

1 accepted

1 vote
Answer accepted

Hello @shivprasad hattaraki

Which version of jira do you use?

try this code 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

log.debug "Starting postfunction..."
if (issue.isSubTask()) {
log.debug "Issue is subtask, leaving."
return
}

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfCategory = customFieldManager.getCustomFieldObjectByName("Po Region")
log.debug "Found customfield ${cfCategory}."
def category = (issue?.getCustomFieldValue(cfCategory) as Option)?.value
log.debug "Got category ${category}."

def userToReassign = issue.getAssignee()
log.debug "Got assignee ${userToReassign}."
def userManager = ComponentAccessor.getUserManager()

switch (category) {
case "Bengaluru":
log.debug "Getting user for Desktop category."
userToReassign = userManager.getUserByKey("shivprasad.hattaraki")
break
case "Mumbai":
log.debug "Getting user for Network category."
userToReassign = userManager.getUserByKey("avinash.deshpande")
break
}
log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)

 

and place it in postfunction, before change history transition

Thank you Mark

Its working fine now.

Hi Mark,

I want to assign an issue automatically to some user based on description entries and auto-set labels to that issue. Can this be possible using the post function script?

Regards,

Satya Prasad

@Mark Markov 

THANKS A TONN! 

I have used the above code for my application/project in JIRA. 

It worked :) :) :)

very much grateful to you. 

thanks again

Sridevi

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you