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

This widget could not be displayed.
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)

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

226 views 3 0
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