Forums

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

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

shivprasad hattaraki
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 18, 2018

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
Mark Markov
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 19, 2018

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

shivprasad hattaraki
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 19, 2018

Thank you Mark

Its working fine now.

Satya Prasad Chilukuri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 14, 2021

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

sridevi koneru
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 31, 2022

@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
AUG Leaders

Atlassian Community Events