Hey,
what I'm trying to do is this:
I have an issue with a number of epics linked to that issue. The epics use the Story Point field. Now I'd like to calculate the aggregated story points and show them in the main issue. Is this possible? I found example Codee from Jamie that seems to do kind of what I want...
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def totalRemaining = 0 issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> if (issueLink.issueLinkType.name == "Comprises") { def linkedIssue = issueLink.destinationObject totalRemaining += linkedIssue.getEstimate() } } return totalRemaining ? componentManager.getJiraDurationUtils().getFormattedDuration(totalRemaining) : null
Cheers Christian
Community moderators have prevented the ability to post new answers.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def cfManager = ComponentManager.getInstance().getCustomFieldManager() double totalSP = 0 customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points"); log.debug("${customField.id}") issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "Logische Verbindung") { log.debug("Link of type ${issueLink.issueLinkType.name} from ${issueLink.sourceObject} to ${issueLink.destinationObject}")} log.debug("${issueLink.destinationObject.getCustomFieldValue(customField).toString()}") def SP = issueLink.destinationObject.getCustomFieldValue(customField) ?: 0 totalSP += SP } return totalSP
Hoping some body can help, I want to use the above script, but only sum as specific sub task like "BUILD". Any help would be much appreciated. Not sure how to make this Sub Task specific: issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "BUILD") { def SP = issueLink.destinationObject.getCustomFieldValue(customField) ?: 0 totalSP += SP } } return totalSP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you are talking about all subtasks of issue type BUILD you can get them like this issue.subTaskObjects.findAll{it.statusObject.name == 'BUILD'}.each{ subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP }
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 answer. It did not quite work. I did not get a sum for the subset of subtasks defined. If I did this I got a sum of all the parents subtasks: issue.subTaskObjects.findAll{ subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aah.. sorry, it's not statusObject (that's for the status...), it's issueTypeObject. So issue.subTaskObjects.findAll{it.issueTypeObject.name == 'BUILD'}.each{ subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP } should do the job.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please provide the complete source of your script and what kind of error leads you to "did not seem to work". Is the custom field name correct? Is the issue type name correct? Are there any log file entries?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Henning, This returns 0 although there are subtasks of type BUILD: import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def cfManager = ComponentManager.getInstance().getCustomFieldManager() double totalSP = 0 customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points"); issue.subTaskObjects.findAll{it.issueTypeObject.name == 'BUILD'}.each { subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP } return totalSP This returns 5, because it is summing all of the subtasks: import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def cfManager = ComponentManager.getInstance().getCustomFieldManager() double totalSP = 0 customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points"); issue.subTaskObjects.findAll { subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP } return totalSP Again, I appreciate your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please try this and report back what subTasks it reports in the log. import com.atlassian.jira.component.ComponentAccessor def cfManager = ComponentAccessor.getCustomFieldManager() double totalSP = 0 def customField = cfManager.getCustomFieldObjectByName("Story Points") def subTasks = issue.subTaskObjects log.error "subTasks: ${subTasks.issueTypeObject.name}" subTasks.findAll{it.issueTypeObject.name == 'BUILD'}.each{ subtask -> def SP = subtask.getCustomFieldValue(customField) ?: 0 totalSP += SP } return totalSP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First, you should get access to the log files because this is a important resource of information if you are scripting your system... In the meantime try import com.atlassian.jira.component.ComponentAccessor def issue = ComponentAccessor.issueManager.getIssueObject('ABC-123') def subTasks = issue.subTaskObjects return "subTasks: ${subTasks.issueTypeObject.name}" within the Script Console after replacing ABC-123 with a meaningful issue key on your system.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That WORKED! Thank you, my stupid mistake as the IssueType was "Build" not "BUILD". I have two more conditions if you can help me with... #1 - add Story Points if the sub-task has not been resolved (check that the resolved date has a value) #2 - Validate that the Fixversion is a specific value Thank you Henning for all your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi James, glad it's working now. Should should take a look at the API documentation (https://developer.atlassian.com/static/) where you can get useful information about the possibilities. Regarding your conditions take a look at the Issue object (https://developer.atlassian.com/static/javadoc/jira/6.4.1/reference/com/atlassian/jira/issue/Issue.html). Here you see that you can get the resolution date via getResolutionDate(). In Groovy you can omit the "get" at the beginning and the () at end if the method don't has any arguments. So you can write if (!issue?.resolutionDate) { // the conditional code her } The question mark is to ensure that you don't get a NullPointerException. For the FixVersions the method is getFixVersions() and returns a collection of Version objects. If you have a Version (https://developer.atlassian.com/static/javadoc/jira/6.4.1/reference/com/atlassian/jira/project/version/Version.html), you can get its name through getName(). In Groovy you don't have to go though every returned version on its own, you can write if (issue?.fixVersions?.name?.contains('Your Version 1.2')) { // the conditional code her } issue?.fixVersions?.name returns a collection of names of the FixVersions of the issue. Have fun, Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This all worked great! I have been able to accomplish what I wanted and create some great real time dashboards for my leadership. I had another question =) What if I want to compare that the subtask DueDate is less than the release date of a particular FixVersion? I'm not sure how to return the Release Date for a specific FixVersion even if it is not the same as the subtask. Henning you have been a wealth of information, and I really appreciate all the help. ~Jim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's kind of hard for other people to help on this question because it requires reading and understanding a long history. I recommend you create a new question, with just your new question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie is right, please create a new question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your cf could also be null, and note that getCustomFieldValue will be null if not set, and if you add that you will get an npe. So use:
def SP = linkedIssue.getCustomFieldValue(cf) ?: 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For wich row is the NPE? First thing could be getOutwardLinks(), this should be secured wit a "?" before the dot (...getOutwardLinks(issue.id)?.each...).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's what I have now resulting in a null pointer:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def cfManager = ComponentManager.getInstance().getCustomFieldManager() def totalSP = 0 issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> if (issueLink.issueLinkType.name == "Logische Verbindung") { def linkedIssue = issueLink.destinationObject cf = cfManager.getCustomFieldObjects(issue).find {it.name == 'Story Points'} def SP = linkedIssue.getCustomFieldValue(cf) totalSP += SP } } return totalSP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to get the customfield through the CustomfieldManager like this
cf = cfManager.getCustomFieldObjects(issue).find {it.name == 'Story Points'}
and use this for getCustomFieldValue().
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like this right now
import com.atlassian.jira.ComponentManager
def componentManager = ComponentManager.getInstance()
def issueLinkManager = componentManager.getIssueLinkManager()
def totalSP = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Logische Verbindung") {
def linkedIssue = issueLink.destinationObject
def SP = linkedIssue.getCustomFieldValue("customfield_10002")
totalSP += SP
}
}
return totalSP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting the custom field value. It's the customfield_10002
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So you just need to make some minor changes to sum the story point custom field, and remove the duration formatting... which bit are you stuck on?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.