It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy Post Script to Assign a User based on a Customfield.

Matthew Noel Feb 21, 2013

I'm trying to write a simple groovy script, to a assign user based on a custom field option. So far this is my code, but with the logical expression it does not process.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()

CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "CustomField"}

cfwt = issue.getCustomFieldValue(sccField)


if (cfwt == "CustomFieldValue001"){
			issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend001'))
			}
			
else if (cfwt == "CustomFieldValue002"){
			issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend002'))
			}
else if (cfwt == "CustomFieldValue003"){
			issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('vend003'))
			}

4 answers

1 vote
Jeremy Cejka Aug 29, 2013

I assume your example for "CustomField" and "CustomFieldValueBlah" is the "<customfield_id>" and <"customfieldid>-x"?

0 votes
Matthew Noel Feb 21, 2013

I figured it out. The above works

Dan Flint Aug 12, 2013

Hi,

I want to do something very simular to the above - how did you get this to work?

Thanks in advance

Dan

Vijay Sv Jun 04, 2015

Hi, I am doing something similar to this for a cascading field, can please help me out with the workaround. Thanks, Vijay

0 votes
Kishore J Aug 07, 2013

Hi,

I am new to JIRA can you please tell me where to write the above scripts? I need to get the assignee based on the custom value

Benjamin Horst Aug 07, 2013

This is the plugin for it:

https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner

But don't expect really quick results. The documentation of the API and the tool is not the part that recieved the most attention. But when you get to know the Script Runner, you'll love it.

0 votes
Derek Sheeman Apr 23, 2015

I have been trying to make this work as a post function of the create transition but doesn't seem to do anything, I'm wondering what I'm doing wrong as I am extremely new to groovy code. import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.util.IssueChangeHolder ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() IssueManager issueManager = componentManager.getIssueManager() CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Responsible Team"} cfwt = issue.getCustomFieldValue(srcField) if (cfwt == "Analytics"){ issue.setAssignee(ComponentManager.instance.userUtil.getUserObject('john_smith')) }

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

838 views 0 12
Read article

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