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

Crafting a service with JIRA Metadata Plugin

Tanner Wortham Dec 25, 2012


Craft a service to refresh a certain set of project-level data in JIRA. (Version dates to be specific.) Fun facts about this service:

  • Will be crafted with Groovy Runner (cuz it's awesome)
  • Will run once a day
  • The source data is pulled from a database
  • This source data knows which project data to refresh through a a custom project field set by the JIRA Metadata Plugin.

And it's this plugin that's currently the crux of my question. I found this code snippet that explains the proper API call for the plugin, but it assumes you're calling it from a listener or post-function and not a service:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import org.apache.log4j.Category

OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class)
issue.setDescription(osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(issue.getProjectObject(), "accounting.code"))

What I'm really looking for is some API call with this plugin that returns an object of type Project when given a custom field name and custom field value.


  1. Does anyone know if I can use JIRA Metadata Plugin to accomplish my goal?
  2. If not, can anyone think of any creative solutions to accomplish my goal?

1 answer

1 accepted

1 vote
Answer accepted


1. your script-snipplet should work with Groovy Runner.

2. you should ask the ProjectManager to get the Project (Project Object)

e.g. ComponentManager.getInstance().getProjectManager().getProjectObjByKey("ProjectKey") (see: and

3. you can change the medatadata value (custom project field) via api call


osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().save(issue.getProjectObject(), "accounting.code", "the new value"); (see:

hope this will help you out


Tanner Wortham Dec 26, 2012

Thanks, Andreas. We're getting there, but it's not quite what I'm looking for. My source data contains a whole list of projects. This data is tied to the data in JIRA by a metadata field called "Theme Key." Ideally, I would make an API call via JIRA Metadata to a method looking something like this:

Project getProject (String customFieldName, String customFieldValue)

My code would never need to modify the metadata only use it to find which project to update. In short, this is what I want my code to do:

  1. Service starts.
  2. Service grabs first row of data from source database.
  3. Service figures out which project to update by finding the proper theme key.
    1. (This step right here is where I need that getProject API call I mentioned above.)
  4. Service updates some project-level information using JIRA's API.
  5. Service grabs next row of data. Go to Step 3.
  6. Service ends when all source data has been consumed.
Tanner Wortham Dec 26, 2012

Also, Andreas, by the looks of it, this guy might do the trick:

Collection<JiraMetadata> getMetadata(ObjectenrichedObject);
But that's only if:
  1. That collection can be unwrapped to return me the proper project.
  2. I can figure out how to properly feed it that enriched object.

The enriched object must be a project or version object. The collection will be all metadata values for this project/version object

You can iterate over all projects.something like:

for (Project p : ProjectManager.getProjectObjects()) {
if ("the value ".equals(metadataService.getMetadataValue(p, "theme"))) {

Tanner Wortham Dec 26, 2012

In that case, getMetadata won't do the trick. Is there anything in JIRA Metadata that will, Andreas?

Tanner Wortham Dec 26, 2012

brilliant. i hadn't thought to tackle the problem from the other direction. That should do nicely. Thank you!! :)

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

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

174 views 2 7
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