Static type checking failed in script editor in Script Runner plugin while using get method

Hitendra Chauhan January 8, 2020

I am new to Script Runner and trying to just get Flagged custom field. the following code is copied from internet and read somewhere that get method is automatically available in the console, but it seems it is not.

Can some one help ?

Code:

def flaggedCustomField = get("/rest/api/2/field").asObject(List).body.find {
(it as Map).name == 'Flagged'
} as Map

 

Error:

2020-01-08_16-27-01.png

2020-01-08 09:19:38,743 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2020-01-08 09:19:38,744 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.get() is applicable for argument types: (java.lang.String) values: [/rest/api/2/serverInfo] Possible solutions: get(java.lang.String), getAt(java.lang.String), grep(), put(java.lang.String, java.lang.Object), grep(java.lang.Object), wait() at Script749.run(Script749.groovy:1)

 

1 answer

1 accepted

0 votes
Answer accepted
brbojorque
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 8, 2020

Hi @Hitendra Chauhan ,

The code you provided only works in Jira Cloud ScriptRunner.

Here's the equivalent code for Jira Server.

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customFields = customFieldManager.getCustomFieldObjects()
log.debug(customFields)
def flaggedCF = customFields.find{ it = "Flagged" }
flaggedCF

Suggest an answer

Log in or Sign up to answer