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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 27, 2018

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

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 28, 2018

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
AUG Leaders

Atlassian Community Events