Static Type Checking Error for MetadataService

Akhil Jain January 30, 2018

I have a Custom Script Post Function, which gets executed everytime issue is created.
I want to retrieve Default Value for a field from Metadata service if project code is not provided. Below is my code

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.osgi.container.OsgiContainerManager

OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class)
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()

CustomField projectCodeField = customFieldManager.getCustomFieldObjectByName("Project Code")
Object projectCodeFieldValue = issue.getCustomFieldValue(projectCodeField)
if(projectCodeFieldValue == null) {
def projectCodeFieldConfig = projectCodeField.getRelevantConfig(issue)
def metaDataService=osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService()
def projectCodeFieldNewValue = ComponentAccessor.optionsManager.getOptions(projectCodeFieldConfig)?.find { it.toString()==metaDataService.getMetadataValue(issue.getProjectObject(), "Default Project Code")}
issue.setCustomFieldValue(projectCodeField,projectCodeFieldNewValue)
}

 
I get error at line 15 - "Static Type Checking"


static type checking.png

 

What needs to be done to fix it.
I cannot import com.osoboo.jira.metadata.MetadataService as it unable to import.
unable to import.png

1 answer

1 accepted

1 vote
Answer accepted
Akhil Jain January 31, 2018

As found in the ScriptRunner Notes, 
Shouldn't worry about Static Type Checking that much

See the below image for more clarity

static type checking-scriptrunner.PNG


Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events