Hi Elita,
Here is what I am trying to do:
I want to create a custom field “Calculated End Date” to be imported as a dimension. It should take one of the following values in this order:
- If a Story has a ‘Target end’, then take that value.
- Else, look at all sprints the Story has been part of and use the Sprint end date for the last Sprint the Story is part of.
- Else, take the value of the Target End of the parent Epic, if it exists.
I do not wish to do these calculations at the front end to avoid slowing reports down at the execution time. I am using the following code to create the custom field:
var sprints = issue.fields.customfield_10004; // Sprint custom field ID
var sprintEndDate = null;
if (sprints) {
// Iterate over the sprints to find the active one or the one that has the most recent end date
for (var i = 0; i < sprints.length; i++) {
var sprint = sprints[i];
// Parse the sprint data
var sprintAttributes = sprint.match(/\[id=(.*),rapidViewId=(.*),state=(.*),name=(.*),startDate=(.*),endDate=(.*),completeDate=(.*),sequence=(.*)\]/);
if (sprintAttributes && sprintAttributes[6]) {
// Sprint end date is in position 6 after splitting the attributes
var endDateStr = sprintAttributes[6];
// Check if the sprint has ended (i.e., has a complete date)
if (endDateStr && (!sprintEndDate || endDateStr > sprintEndDate)) {
sprintEndDate = endDateStr;
}
}
}
}
var targetEndDate = issue.fields.customfield_17503 ? issue.fields.customfield_17503 : null;
var epicLink = issue.fields.customfield_10000 ? issue.fields.customfield_10000 : null;
var parentLink = issue.fields.customfield_17501 ? issue.fields.customfield_17501 : null;
var calculatedEndDate = null;
if (sprintEndDate) {
calculatedEndDate = sprintEndDate;
} else if (targetEndDate) {
calculatedEndDate = targetEndDate;
} else if (epicLink || parentLink) {
// Assuming that the ‘Target End Date’ for the linked epic or parent issue has already been imported to eazyBI
var linkedIssueKey = epicLink || parentLink;
// The next line of code does not work as you can see that Target End Date of the Epic does not appear as property in the Story. Please see the properties field of the test story shared after the code.
var linkedIssueTargetEndDate = issue.properties[linkedIssueKey + ’ customfield_17503’];
if (linkedIssueTargetEndDate) {
calculatedEndDate = linkedIssueTargetEndDate;
}
}
return issue.fields.customfield_calcenddate = calculatedEndDate ? new Date(calculatedEndDate) : null;
I am sharing part of results of this code on a test ‘Story’ issue:
“customfield_calcenddate”: null
},
// The properties field is empty
“properties”: {
“jpo-issue-properties”: {}
},
“changelog”: {
“histories”:
}
}
So, how do I access ‘Target End Date’ from Epic in a Story object? Please let me know if there is another way to accomplish it.