Forums

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

how to get issue type name by issue type id? (besides of of SQL request to DB)

Ignat March 16, 2022

Hello everyone.

I use createIssue() routine in my script. This routine gnneeds the issue type name as an input.

To make the script resistant to issue type renaming I'd like to put issue type id instaead of issue type name in it. I know how to find out the id, but do do not the convinient way to transform it to name

3 answers

1 accepted

0 votes
Answer accepted
Ignat April 19, 2022
function getIssueTypeNameById(int issueID) {
string issueTypeName;
string query =
"SELECT \"PNAME\" FROM \"ISSUETYPE\" WHERE \"ID\" = " + issueID;
// runnerLog(query);
issueTypeName = sql("JiraDS", query);
if (iissueTypeName == "") {
issueTypeName = "not found";
}
return issueTypeName;
}
1 vote
Antoine Berry
Community Champion
March 16, 2022

Hello @Ignat ,

I believe that you can use the id instead of the name when creating the parameters for the issue creation : 

 

def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()

MutableIssue newIssue = issueFactory.getIssue()
newIssue.setRepoter(....
...)
newIssue.setIssueTypeId(12345)

Map<String,Object> newIssueParams = ["issue" : newIssue] as Map<String,Object>

issueManager.createIssueObject(user, newIssueParams)

Note that createIssueObject() should be better as it is not deprecated.

Ignat April 19, 2022

sorry. I havn't mentioned - I usr SIL. not groovy

0 votes
Piyush A (STR)
Community Champion
March 16, 2022

Try to get the issue types of the project and then get the id Vaue

https://docs.atlassian.com/software/jira/docs/api/REST/7.11.0/#api/2/project-getProject

Ignat April 23, 2022

it was my first thought. but rest is slow and I ended upt with direct SQL request to db solution

Suggest an answer

Log in or Sign up to answer