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

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 03, 2019 in Marketplace Apps

How to estimate projects more accurately?

Gaining insight into your team’s effectiveness and choosing the right estimation technique.   Estimating projects is hard. It is because people have the tendency to underestimate the time thin...

286 views 2 8
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