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

Try to get CustomFieldManager by using this syntax:

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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,331 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot