Forums

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

Auto assign based on custom field.

SmaatHub January 7, 2020

Hi,

I'm trying to use these script for Auto Assign based on the custom field"Drop-down menu"

but it's not working with me.

Ps: Jira software version 7.12.1 and the post function is Scripted (Groovy) operation on issue (JMWE add-on) 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption


String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Departments")
def cfDepartments = issue.getCustomFieldValue(cf)
switch(cfDepartments){
case "Influencer Relations": userName = "INF_BP";break;
case "Client Services": userName = "CS_BP";break;

}
log.error(userName)
log.error(cfDepartments);
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(ComponentAccessor.getUserManager().getUser(userName))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

 

--------------------------------------------------------------------------------------------------

 

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("Departments")
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 "Influencer Relations":

userToReassign = userManager.getUserByKey("INF_BP")
break
case "Client Services":

userToReassign = userManager.getUserByKey("CS_BP")
break
}
log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)

 

2 answers

0 votes
John Funk
Community Champion
January 7, 2020

Hey @SmaatHub - can you describe exactly what you are trying to do without the code?

SmaatHub January 7, 2020

I'm trying to Auto Assign the ticket based on the custom field"Drop-down menu"

Ex: if the requester of ticket chooses his department from the drop-down menu like Client engagement the assignee goes to CE-BP and so on in other choices.

 

John Funk
Community Champion
January 8, 2020

I know that can easily be done with the Automation For Jira add-on. If the value of a field changes, you can have different actions that take place - for instance, setting the value of another field. 

0 votes
SmaatHub January 7, 2020

Any help?

Suggest an answer

Log in or Sign up to answer