Scripted field throwing a lot of errors to log

Hi,

need help with a script that looks like this:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user.ApplicationUsers
 
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()

def cf1 = customFieldManager.getCustomFieldObjectByName("Acceptance Tester")
def AT_tester = issue.getCustomFieldValue(cf1)

if (AT_tester != null){
    return AT_tester
    }
else if (issue.assignee != null)
    {
        return ApplicationUsers.from(issue.assignee)
     }

The problem in the script seems to start from defining the customFieldManager, but unfortunately i aint that prolific in scripting and would need help fixing it.

The errors thrown look like this :

 at Script39.run(Script39.groovy:9)
2017-09-14 11:48:00,038 IssueIndexer:thread-9 ERROR user 703x625x2 amexwj 10.65.108.20,194.126.96.20 /secure/admin/IndexReIndex.jspa [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: notimportant, field: scriptedATtester
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.ComponentManager.getCustomFieldManager() is applicable for argument types: () values: []


Thanks in advance

1 answer

0 vote

What version of Jira are you on here?

Hi,

Thanks for the reply and sorry for not including it in the first place, we are running Jira v7.1.9 right now.

You weren't to know the version was going to matter!

For 7.x, you can use ComponentAccessor instead of ComponentManager

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

Thanks for that, truly valuable knowledge, that i had missed. But. The issue with the script still remains. Changed the script to this:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)

def cf1 = customFieldManager.getCustomFieldObjectByName("Acceptance Tester")
def AT_tester = issue.getCustomFieldValue(cf1)

if (AT_tester != null){
    return AT_tester
    }
else if (issue.assignee != null)
    {
        return ApplicationUsers.from(issue.assignee)
     }

And it throws an error now on "return AT_tester" line : [Static type checking] - Cannot return value of type java.lang.Object on method returning type com.atlassian.jira.user.ApplicationUser @ line 14 column 9

Also still an error on "return ApplicationUsers.from.issue.assignee" line.

Could you help out with this too?

I think you need to convert what you find in those fields into the expected return type for the field.

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 Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

177 views 0 4
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