Groovy change assignee based on custom field value

Dan Flint
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 15, 2013

Hi,

I have been trying to change the assignee of an issue on the create transition based on the value of a custom field.

The below is the groovy script I have altered from another post.

This does not seem to work, as the records still get assigned to the default assignee - could someone possibly help?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
MutableIssue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager()
// Get the Request For Custom Field
CustomField customField = cfManager.getCustomFieldObject(10346)
// Get the value of the Request For
Object customFieldValue = issue.getCustomFieldValue(customField)
if (customFieldValue ='Content')
UserManager userManager = UserManager.getInstance();
User usera = userManager.getUser("forename.surname");
issue.setAssignee(usera)
issue.store()

Any help would be greatly appreciated

Dan

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Dan Flint
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.
September 22, 2013

I ended up solving this by using a scripted custom field, as I do not have access to be able to put scripts on the server where they cna be accessed.

I used the script below to calculate the user, then i used a post function to copy the field to the assignee field on the create step. Note the post function was palced after the orignal create, as otherwise this would not work.

I know this is probably not the best way to implement this functionality in the long term, I intend to replace this with a script when I have access to save these on the server, but for now this should suffice.

import com.atlassian.jira.user.UserUtils

def cf_Assignee = getCustomFieldValue("Custom Field Name").getValue()



if (cf_Assignee == "Value 1") {

return UserUtils.getUserManager().getUser("Firstname.Surname")

}else if (cf_Assignee == "Value 2") {

return UserUtils.getUserManager().getUser("Firstname.Surname")

}else if (cf_Assignee == "Value 3") {

return UserUtils.getUserManager().getUser("Firstname.Surname")

}else {

return UserUtils.getUserManager().getUser("Firstname.Surname")

}

TAGS
AUG Leaders

Atlassian Community Events