I try to get all IssueTypes for a certain IssueTypeScheme.
Here is what I have so far:
import com.atlassian.jira.component.ComponentAccessor
def schemeManager = ComponentAccessor.issueTypeSchemeManager
def sb = new StringBuilder()
schemeManager.getAllSchemes().each {
try{
if(it.getAssociatedProjectObjects().size() == 0 && !it.isGlobal()) {
sb.append("${it.name}")
sb.append("|${it.getAssociatedIssueTypes()}<br/>\n")
}
}
catch(Exception e) {
sb.append("Error: " + e + "<br/>\n");
}
}
return sb.toString()
This results in a list of the expected IssueTypeSchemes (all with no associated projects) but I always get an empty result for my List of Issue Types inside that Scheme.
Edit: on top of that, I'd like to delete all IssueTypeSchemes w/o associated projects - but I didn't found sth. like a "removeIssueTypeScheme" method for my schemeManager.
Hello @Steffen Becker
Did you try adding logging and see whats getting printed or try the code in the script console
try{
if(it.getAssociatedProjectObjects().size() == 0 && !it.isGlobal()) {
sb.append("${it.name}")
// print the contained issuetypes
it.getAssociatedIssueTypes().each {
//print here
it.getName()
}
}
}
I run in the script console.
Your suggestion prints out nothing.
Also the following prints out "0" for all schemes (but ofc all my IssueTypeScheme contain some IssueTypes):
it.getAssociatedIssueTypes().size()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please share the screenshot of the exact code and the console output. Because it's hard to beleive that the issueType scheme contains the issueTypes yet it's displayed as 0 in the logs.
schemeManager.getAllSchemes().each {
print it.getName() // here you can check if you see the name of all the issueTypeschemes and then see the issueTypes contained in them
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Steffen Becker
Thanks for sharing the screenshot, just a hunch, I feel that the method
"getAssociatedIssueTypes" is returning 0 because "getAssociatedProjectObjects" is returning 0 , i.e. the method "getAssociatedIssueTypes" returns only the issueTypes which are actually part of an scheme which is associated with an project.
Can you remove the criteria "getAssociatedProjectObjects.size() ==0" and see if there is output for the method "getAssociatedIssueTypes" because if there is an output in this case then it will be bug in the API as there seems to be no way to get issueTypes of schemes which are not having any associated projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your support so far!
When I just change the == 0 condition to != 0 , then I get the following output:
[Scheme] Agile Scrum Issue Type Scheme
[IssueTypes]
Error: java.lang.NullPointerException: Cannot invoke method getName() on null object
[Scheme] APM: Scrum Issue Type Scheme
[IssueTypes]
Error: java.lang.NullPointerException: Cannot invoke method getName() on null object
[...]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know if it matters, but I'm using a ScriptRunner evaluation licence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Steffen Becker
I did some testing on my end and here's what I found
The method "getAssociatedIssueTypes()" for FieldConfigScheme always returns NULL irrespective of associated projects or no associated projects. I don't know why it always returns null but that seems to be the case. I am using 7.11 version of Jira.
In order to get the issueTypes of a projects I used below code
def schemeManager = ComponentAccessor.issueTypeSchemeManager
def projectManager = ComponentAccessor.projectManager
def project = projectManager.getProjectByCurrentKeyIgnoreCase("ABC")
def fieldScheme = schemeManager.getConfigScheme(project)
StringBuilder builder = new StringBuilder()
schemeManager.getIssueTypesForProject(project).each {
builder.append(it.getName())
}
/* this returns the issue types correctly */
return builder.toString()
In the above code the variable "fieldScheme" is redundant because even after I do
return fieldScheme.getAssociatedIssueTypes()
I always get null thus in order to get issueTypes associated with a project (not a scheme) I used
schemeManager.getIssueTypesForProject(project).each {
builder.append(it.getName())
}
Thus, I don't know how in the APIs we can get issueTypes which are associated with a issueTypeScheme directly instead of going via querying the project route just like I have done it.
May be you can use the same approach as I have used, in the code get the associated projects using
fieldScheme.getAssociatedProjectObjects()
And then use below code for each project Object, this approach should definitely work!
schemeManager.getIssueTypesForProject(project).each {
builder.append(it.getName())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the above script in my script runner console and i get null value as a result.
Kindly suggest a way. To get the issue type of the project and calculation for the field values inside a particular issue type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had the same problem with JIRA 8.21 and found a solution to determine all issue types for all issue type schemes.
import com.atlassian.jira.component.ComponentAccessor
def schemeManager = ComponentAccessor.issueTypeSchemeManager
List Types
StringBuilder builder = new StringBuilder()
schemeManager.getAllSchemes().each{ it ->
Types=schemeManager.getIssueTypesForScheme(it) as List
builder.append(it.getName()+"=> "+Types.toString())
}
return builder.toString()
Regards
Hannes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.