I need to get sprint names of a defined issue. At first, I thought that this can be done as all custom fields like this:
private static final long SPRINT_CUSTOM_FIELD_ID = 11160; // ID of Sprint CF in Jira 6.1.5;
CustomField customFieldSprint = customFieldManager.getCustomFieldObject(Long.valueOf(SPRINT_CUSTOM_FIELD_ID));
log.debug("Issue: "+ issue.getKey() +"Sprint Value: "+ getCustomFieldStringValue(issue, customFieldSprint));
Where getCustomFieldStringValue is the following:
public String getCustomFieldStringValue(Issue issue, CustomField customField) {
String customFieldStringValue = "";
Object value = issue.getCustomFieldValue(customField);
if(value == null){
customFieldStringValue = "";
}
else if(value instanceof Option) {
customFieldStringValue = ((Option) value).getValue();
}
else if(value instanceof String) {
customFieldStringValue = (String) value;
}
log.debug("Custom Field " + customField.getName() + " has the following string value: " + customFieldStringValue);
return customFieldStringValue;
}
But, I obtained an empty value.
I have noticed that the method getSprintsForIssue of com.atlassian.greenhopper.service.sprint.SprintIssueServiceImpl gets sprints for a defined issue, but I'm not be able to use it (it seems that there'no public services for this as mentioned in https://answers.atlassian.com/questions/92681/how-to-get-sprints-using-greenhopper-api). Can you please advise?
Thanks,
Rosy
Thanks Marten.
You are right! I only imported green hopper plugin classes in my pom.xml and defined this Class as a Component in my atlassian-plugin.xml. I wasn't aware of this tricky code.
Many Thanks,
Rosy
Hey Marten,
I have the version 6.1.5, but SprintManager doesn't work with this version as well.
I tried your code and it works perfectly! :)
Thanks a lot for your help,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rosy,
always happy to help. but as far as I know SprintManager should work in your version. It is just very tricky to get it. Standard import via the pom file won't work, you have to do some more elaborated stuff, like posted in this question
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rosy,
unfortunatly you are right, the SprintIssueService is not a public service. However, depending on your version of Jira and Agile you might be able to access the SprintManager class, which might be useful to your problem. But this only works for Agile and Jira versions <6.2.
In regards to your problems with the custom field, the content of this field is an ArrayList of the class Sprint. therefore your code will probably just keep and return its inital empty string. To access the content of the field you could try some code similar to this:
private void setSprintData(){ ArrayList<Sprint> list = (ArrayList<Sprint>) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint").getValue(getIssue()); if(list!=null){ Iterator<Sprint> it = list.iterator(); String name = ""; Long id = Long.MIN_VALUE; while(it.hasNext()){ Sprint next = it.next(); if(id<next.getId()){ id=next.getId(); name = next.getName(); } } sprintName = name; sprintId = id; }else{ sprintName = ""; sprintId = -2L; } }
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.