In ScriptRunner for JIRA: Cannot find method getFieldByName


I am trying to follow an example from the ScriptRunner's manual ("Select Lists with Other") and get a field object:

def componentField = getFieldByName("product_component")

I paste it to the script console and immediately get an error, "Cannot find matching method".

Shall I import some library?

I added the following imports:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField

def componentField = getFieldByName("product_component")

but it did not help.

Please assist.





1 answer

0 vote

You can only use getFieldByName and the various other methods in the documentation in that section with the behaviours functionality.

If you need to get a custom field from the Script Console you should use:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def issueKey = "TEST-1"
def issue = issueManager.getIssueObject(issueKey)

def productCf = customFieldManager.getCustomFieldObjectByName("product_component")

def productValue = issue.getCustomFieldValue(productCf)

Hope this helps.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
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