Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA Scriptrunner - possible to retrieve an object by ID instead of key?

Carsten Kiess April 23, 2019

I have some IDs (6 digit integer) and would like to understand which object they represent.

I am looking for something like:

  • anyMethodToFindObjectByID("123456")
    • which would return me e.g. an issue object
      • for which in turn I can retrieve the key e.g. "PRO-987".

Is there any such method? Or any alternative? Or are these IDs not accessible through the API? I can get the ID for a known object but apparently I can not select such an object initially by using the ID.

 

Thanks in advance! Carsten

2 answers

1 accepted

1 vote
Answer accepted
Payne
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.
April 23, 2019

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject(160778)

return issue.key

Carsten Kiess April 24, 2019

Thanks Payne! This pointed me into the right direction. Cheers, Carsten

0 votes
PD Sheehan
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.
April 23, 2019

I don't know of a way to do that.
Plus different object may end up with the same id. 
You really need to understand the context first.

One could create a script that takes an id, then iterate through all the common object types and try to obtain each object type from the given id and return all the type/class of all objects that were found matching that ID.  But that likely doesn't exist.

You might have more luck asking the community where your specific id came from by explaining where/how you got it.

Carsten Kiess April 24, 2019

Hi Peter, thanks, that's along the line I was thinking about - taking the ID and run it against the most common types as a tool to analyse issues. Will dig deeper into it. Cheers Carsten

Suggest an answer

Log in or Sign up to answer