Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,487
Community Members
 
Community Events
168
Community Groups

Get projectID for versionID in scriptrunner

Edited

I have a versionID and I want to retrieve the project's ID, name, Key, Lead, Category, etc

I retrieve the projectID with a versionID via http/REST with:

rest/api/2/version/{versionId}

I can then retrieve the other project details from

rest/api/2/project/{projectId}

... How would I go about retrieving the same information from within scriptrunner script, without using http requests?

I've tried using the ComponentAccessor's versionManager like this:

import com.atlassian.jira.component.ComponentAccessor
def ProjectManager = ComponentAccessor.projectManager
def VersionManager = ComponentAccessor.versionManager

long version = 23958
def versionObject = VersionManager.getVersion(version)
log.warn(versionObject)

 

...but I can't figure out how to get the projectID from the version object in this manner. 

1 answer

1 accepted

0 votes
Answer accepted

Charles,

Is this for ScriptRunner for JIRA Server?

If so, you should should be able to call getProjectId() on the Version object.

import com.atlassian.jira.component.ComponentAccessor
def ProjectManager = ComponentAccessor.projectManager
def VersionManager = ComponentAccessor.versionManager

long version = 23958
def versionObject = VersionManager.getVersion(version)
log.warn(versionObject.projectId)

See https://docs.atlassian.com/software/jira/docs/api/7.8.0/com/atlassian/jira/project/version/Version.html

Thanks Joshua!

I actually used .getProjectId() on the version object for my final script (putting that into a new variable)

Now I know to keep digging in that api doc :)

No problem. If you plan to write a lot of scripts, you might consider following our "Setting up a dev environment guide"

https://scriptrunner.adaptavist.com/latest/jira/DevEnvironment.html#_connecting_intellij_idea_with_the_atlassian_source_code

That functionality makes it a lot easier to see which methods are available for your objects (like Version).

@Joshua Yamdogo _ Adaptavist 

How can I get "project ids" from a collection of version ids?

VERSIONOBJECT.png

Its necessary use for.each ? how I can show a later out the for.each the list with projects ids ?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events