Groovy change assignee based on custom field value but not working

Where is the problem ? How Can I Solution This problem ? 

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
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.crowd.embedded.api.User

CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "proje"}
def cfwt =(Option) issue.getCustomFieldValue(srcField)
if(cfwt!=null){
def cfValue=cfwt.getValue()
log.debug "my Value is ${cfValue}."

switch (cfValue) {

case 'DPT': userToReassign = ComponentManager.getInstance().getUserUtil().getUser("xx.xx")

case 'YGLS': userToReassign = ComponentManager.getInstance().getUserUtil().getUser("xx.yy")
}

issue.setAssignee(userToReassign)

issue.store()}

 

Error

No such property: customFieldManager for class: Script45

groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script45 at Script45.run(Script45.groovy:13)

2 answers

1 accepted

0 vote
Peter Bengov Community Champion May 10, 2015

Try to get CustomFieldManager by using this syntax:

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
Peter Bengov Community Champion May 10, 2015

Try also to use: def cfwt = issue.getCustomFieldValue(srcField).getValue() Instead of: def cfwt =(Option) issue.getCustomFieldValue(srcField)

I Try But Now Error Message ;

Error Creating İssue : Property 'cfValue' not found.

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
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.crowd.embedded.api.User

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "proje"}
def cfwt =(Option) issue.getCustomFieldValue(srcField)
if(cfwt!=null){
def cfValue=cfwt.getValue()
log.debug "my Value is ${cfValue}."

switch (cfValue) {

case 'DPT': userToReassign = ComponentManager.getInstance().getUserUtil().getUser("xx.xx")

case 'YGLS': userToReassign = ComponentManager.getInstance().getUserUtil().getUser("xx.yy")
}

issue.setAssignee(userToReassign)

issue.store()}

 

 

I am running into this same issue. Did you ever figure it out?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Service Desk

Wy are we still using email for Service Desk workflows?

...attest to the experience of an urgent approval that gets lost in the boss’s inbox and requires that special “Please Approve” email or text message. In an age where we have distributed teams...

113 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you