Issue with calling class/method in a custom Scriptrunner method Edited

Hello when writing a custom setGalaxy method like below


1  import com.atlassian.jira.issue.ModifiedValue
2  import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
3  import com.atlassian.jira.issue.MutableIssue
4  import com.atlassian.jira.issue.CustomFieldManager
5  import com.atlassian.jira.issue.Issue
6  import com.atlassian.jira.component.ComponentAccessor
7  import com.atlassian.jira.issue.label.LabelManager
9  MutableIssue issue = (MutableIssue) event.issue;
11 CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
12 def groupManager = ComponentAccessor.getGroupManager()
14 def setCF(String updatedValue,String issueSet) {
15    def thisCF = customFieldManager.getCustomFieldObjects(issueSet).find { == 'Some Field'}
16    def fieldConfig = thisCF.getRelevantConfig(issueSet)
17    def setValue = ComponentAccessor.optionsManager.getOptions(fieldConfig).find { it.value == updatedValue }
18    def changeHolder = new DefaultIssueChangeHolder()
19    thisCF.updateValue(null, issueSet, new ModifiedValue(issueSet.getCustomFieldValue(thisCF), [setValue]),changeHolder)
20 }
21 setCF("Potato",issue)

I get the following errors in the method:

Line 15 The variable [customFieldManager] is undeclared and No such property: name for class: java.lang.Object

Line 16 - 19 get other errors due to thisCF not being set. 

Moving customFieldManager into the method doesn't help.

There is a similar issue here but everything is outside the method.


JIRA Software 7.2.4 Scriptrunner 5.0.4

2 answers

Hi John,

The groovy documentation here in section 3.4 explains why you are having the issue your are. Script variables do not require a type definition.

If you define the type (def, CustomFieldManager, e.t.c.) it will define the variable as local and will NOT be available outside the main script declaration (including inside internal methods).

You can fix the problem by taking the type definition away:

cFManager = ComponentAccessor.getCustomFieldManager()

def galaxySet(galaxyName,issueName) {
def galaxyCf = cFManager.getCustomFieldObjects(issueName).find { == 'Galaxy'}

You'll notice that all we need to do is take away the type definition and we get access inside our method.

I get "The variable [cFManager] is undeclared." when I remove the type


Hi John,

I've looked at the linked community post you provided. I've noticed several other issues in the example that you provided. I also can't find the original setGalaxy method in the example that you gave.

Perhaps it would be easier if I understood what you are trying to accomplish with this script. This would make it easier to work around the issues that you are seeing.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,024 views 4 9
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