How to get metadata in groovy postfunction?

Hello!

Could please someone explain the method of obtaining metadata values of Project (by its ID, for example).

Need groovy exaple.

Thank you!

3 answers

1 accepted

This widget could not be displayed.

Based on JM-48 got working mehod:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

import org.apache.log4j.Category
def Category log = Category.getInstance("get.metadata.values.from.project")
log.setLevel(org.apache.log4j.Level.DEBUG)

//processing projectpicker
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfClient = customFieldManager.getCustomFieldObject("customfield_12700")
def cfClientValue = issue.getCustomFieldValue(cfClient)

def projectManager = ComponentAccessor.getProjectManager()
def projectObject = projectManager.getProjectObjByName(cfClientValue.name)
Issue myIssue = issue
log.debug("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
log.debug("HHH Metadata Value: " + ComponentAccessor.getComponentOfType(myIssue.getClass().getClassLoader().findLoadedClass("com.atlassian.jira.plugin.JiraOsgiContainerManager")).getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(projectObject, "Key"))
log.debug("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
This widget could not be displayed.

Hi,

if you want the ID you can use the following

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.Project;


//Create the project object
Project project = issue.getProjectObject();
//Create project id
Long pr_id = project.getId();

Hi, Kostas,

thank you for answer. No problems with project ID.

But need to get project's metadata values.

There is add-on "Metadata for JIRA", created by @Andreas Spall. This add-on adds some fields to project.

hmm, i see. No idea about about how you could do that.

This widget could not be displayed.

You would have to see how that plugin stores additional data. Most likely OSProperty, in which case:

import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

OFBizPropertyUtils.getPropertySet(project.genericValue)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 11 hours ago in Canada

AUG Lunch Roundtable - August 13 - Highlights

Thanks to everyone who came out today for the lunch AUG - we had some great food and discussion (and ice cream sandwiches to fend off the heat!) The welcome and fun fact was great as well, what an aw...

27 views 1 3
View post

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