Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

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).

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,888 views 11 5
Join discussion

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