Forums

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

Assign issue based on customfield value

Swarna Radha
Contributor
March 27, 2018

Hi,

I have a drop down list - To Queue having values (Service Desk, IT- Imaging and so). If i choose service desk, in the assignee field i should get list of users on the Group Service Desk. I tried to use the script below but i am having an error of deprecation comment in the line - userToReassign = userUtil.getUserObject("Service Desk")

 

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

log.setLevel(Level.DEBUG)

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

def tr = customFieldManager.getCustomFieldObjectByName ("To team")
def trValue = issue.getCustomFieldValue(tr) as String

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


if (trValue == "Service Desk") {
 userToReassign = userUtil.getUserObject("Service Desk")
// issue.setResolution(resolutionManager.getResolutionByName("Closed successful"))}
//issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('john_smith')
}
log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)

 

Kindly let me know what is the new code to replace the above.

 

Thanks

Swarna

2 answers

0 votes
Vasiliy Zverev
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.
March 28, 2018

Here is refacrored version of your code

import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor

log.setLevel(Level.DEBUG)

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

String userToReassign = issue.getAssigneeId()
log.debug "Got assignee ${userToReassign}."

switch( (String) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName ("To team"))) {
case "Service Desk":
// issue.setResolution(resolutionManager.getResolutionByName("Closed successful"))}
issue.setAssigneeId (ComponentAccessor.getUserManager ().getUserByName ("john_smith"))

}

log.debug "Setting user to ${userToReassign}."
issue.setAssignee(userToReassign)
Swarna Radha
Contributor
March 28, 2018

Hi Vasiliy,

 

To Team is a drop down list, i need to choose "Service Desk" which populated all members from "Service Desk"  group in the assignee field. In your code where service desk is assigned to Service Desk group.

 

Thanks

Swarna Radha
Contributor
March 29, 2018

Hi Dave,

 

I am still having error using the following line

userToReassign = ComponentAccessor.userUtil.getObjectByName("Service Desk")

 

Thanks

Swarna

0 votes
Dave Norton
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2018

G'day Swarna,

Looking over the docs, that function has been deprecated in favour of  getUserByKey(String) or getUserByName(String) instead.

Since you probably have a username, you should be able to use the getUserByName method instead. Does this help you move forward with your script? Let me know if it does!

Cheers,
Dave

Swarna Radha
Contributor
March 29, 2018

Swarna Radha 3 seconds ago

Hi Dave,

 

I am still having error using the following line

userToReassign = ComponentAccessor.userUtil.getObjectByName("Service Desk")

 

Thanks

Swarna

Suggest an answer

Log in or Sign up to answer