Need help with Advanced Import JavaScript

Hi All!

We’re using Jira and I’d like to skip importing our “Subtask” issues (cuts the total issue count in half if I do). That part is easy using the JQL additional filter.

The problem I’m having is that I’d like to aggregate any Story Points (and eventually Hours Spent) into the parent Story. I’m trying to test the example for postDocument here and I’m running into several problems.

First, if (issue.fields.subtasks) is returning false for my sample issue, but the REST call from Jira (JIRA_BASE_URL/rest/api/latest/issue/PPP-NNN?expand=changelog) is returning data in subtasks.

Second (if I ignore the first), postDocument is returning 400, yet I can use the PostMan tool and retrieve results.

if (issue.fields.subtasks ) {
// create a post request body
body = {
jql: "cf[12503] > 0 and parent = " + issue.key,
fields: [
“customfield_12503” // custom field Story Points in sub-tasks
]
}

// call post request
response = postDocument(“/rest/api/2/search”, body, {content_type: ‘application/json’});
// there is a response with sub-tasks. get Story Points from any sub-tasks and add to the parent issue
if (response && response.issues) {
for (var i = 0; i < response.issues.length; i++) {
issue.fields.customfield_12503.value += response.issues[i].fields.customfield_12503.value;
}
}
}

The body used in the PostMan tool is:

{
“jql”: “cf[12505]>0 AND parent=DIM-184880”,
“fields”: [
“customfield_12503”
]
}

eazyBI uses JAVA API and builds issue JSON for Jira Server instead of using JIRA default REST API. Therefore, you would like to check the data structure and available fields in Import options for the account > tab Additional options > Custom JavaScript code. You can test it with any issue and check the available data structure.

issue.fields.subtasks is not available in the issue JSON generated by eazyBI.

If you would like to access sub-tasks, you can use issue.fields.issue.links instead. Issue links include sub-tasks as outward issues with issue link name jira_subtask_outward.

However, this is not a suggested way to go.
JavaScript calculated custom fields are the best way on how to precalculate values during import. However, we suggest planning calculations related to issues themselves only. Calculations on any related objects (sub-tasks, linked issues, sprints, fix versions) might not work as expected. And you can get unreliable data at some point. Those objects might change values with a different frequency (update intervals) than issues. Regular imports run incrementally on new or updated issues. Sub-tasks might have different update times than issues, and you can miss changes in sub-tasks with regular imports.

There is no option to make JavaScript code execute any time on any imported issue. We are not planning this to avoid unnecessary performance impact on Jira. The function postDocument also might significantly impact import performance and on Jira in this case in particular.

You can either consider calculating those values with some scripted fields or import Sub-tasks into eazyBI and use calculations and default measures on them in eazyBI.

The overall suggestion is to import all the issues you would like to access in reports, including sub-tasks. This would give all the reporting abilities. I would suggest considering how to limit the imported data set using other filters, for example, time, the project, etc.

In many cases, even with lots of imported issues, there is a way to use eazyBI with good performance. You can check this documentation page on best practices for report creation.

Daina / support@eazybi.com

Thank you Daina!
I believe the documentation mislead me with the example of postDocument - in -re-reading it I see it indicates using the REST API to perform the import, not the Jira data source.

I started reviewing the best practices page a few days ago & will continue down that path.

Function posDocument could be used in Jira imports as well. However, we suggest using it with a caution. In this case, this might not work for a particular scenario - based on Jira import functionality.

You can always post in community some formulas or report definition or reach out to support email if you have some problems with performance. We can check if there are any room for improvements.

Daina / support@eazybi.com