It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Static Type Checking Error for MetadataService Edited

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")}

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

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
Community showcase
Published in Marketplace Apps & Integrations

Marketplace Spotlight: Manage your assets with asset management apps

  The role of IT professionals has become increasingly difficult over the last decade. Our organizations work in an increasingly software-powered world and IT professionals are expected to not...

373 views 3 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you