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 8 9 MutableIssue issue = (MutableIssue) event.issue; 10 11 CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() 12 def groupManager = ComponentAccessor.getGroupManager() 13 14 def setCF(String updatedValue,String issueSet) { 15 def thisCF = customFieldManager.getCustomFieldObjects(issueSet).find {it.name == '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
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 https://community.atlassian.com/t5/Atlassian-Marketplace-questions/Basic-method-to-update-a-custom-f... but everything is outside the method.
JIRA Software 7.2.4 Scriptrunner 5.0.4
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 {it.name == '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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Thanks,
Steve
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.