Custom JavaScript code
You can use custom JavaScript code in the flex.bi account to modify Jira issues field values during import. The JavaScript code will modify the issue JSON object before importing issues into flex.bi account.Â
Custom Javascript code can not be used to create new custom fields for flex.bi. It updates existing fields only.
How to add and validate custom JavaScript code
Custom JavaScript code should be added to each account where you would like to make data modifications. Open Jira import options of the account, in tab Additional options click Add custom JavaScript code to show the code editor.
Then add some Javascript code in the code editor [1]. You can test the code for one sample issue key in the validation area [2]  and see results in the results pane [3] [4].
JavaScript code should be ES5 compliant, ES6 syntax is not supported.
You can use issue
 variable to access received Jira REST API issue JSON object properties and modify or add additional properties. flex.bi will use only custom fields imported into the account. You can see the full Jira issue REST API in the browser. Please open JIRA_BASE_URL/rest/api/latest/issue/PPP-NNN?expand=changelog
 in your browser (where PPP-NNN is issue key) to see sample issue JSON.Â
Save import options after the testing is done and JavaScript works as expected. flex.bi will detect changes in import options and apply the JavaScritp code for any imported issue.Â
Import Summary as an empty string
Here is an example of JavaScript code that will replace the issue summary
 property with an empty string for issues with issue type bug
if (issue.fields.issuetype && issue.fields.issuetype.name == "Bug") { issue.fields.summary = ""; }
Delete custom field values for bug issues
If you would like to delete some field values and do not import them in flex.bi then use undefined
.
if (issue.fields.issuetype && issue.fields.issuetype.name == "Bug") { issue.fields.customfield_NNNNN = undefined; }
Use custom field ID instead of NNNNN in the example above.
Calculate resolution dateÂ
flex.bi creates a default set of measures based on the issue resolution date, for example, Issues resolved, Story Points resolved, etc. If the resolution date is missing in issues in Jira but you would like to have it in flex.bi you can use custom JavaScript code to calculate one. The example below will calculate the missing resolution date for completed issues based on status.
// Resolution date var resolvedStatuses = ["Done","Resolved","Closed","Complete","Fixed"]; // list all statuses representing resolved or closed issue if (!issue.fields.resolutiondate && resolvedStatuses.indexOf(issue.fields.status.name) > -1) { // validations when there is no resolution date for issues in resolved status var resolutionDate = null; var stillOpen = true issue.changelog.histories.forEach(function(history){ history.items.forEach(function(historyItem){ if (historyItem.field == "status") { statusFrom = historyItem.fromString; statusTo = historyItem.toString if (stillOpen && resolvedStatuses.indexOf(statusTo) > -1 && resolvedStatuses.indexOf(statusFrom) == -1) { stillOpen = false; resolutionDate = history.created; } else if (!stillOpen && resolvedStatuses.indexOf(statusFrom) > -1 && resolvedStatuses.indexOf(statusTo) == -1) { stillOpen = true // reopened resolutionDate = null } } }); }); // completed status at the issue creation if (resolutionDate === null && resolvedStatuses.indexOf(issue.fields.status.name) > -1 ) { resolutionDate = issue.fields.created; } if (resolutionDate) { issue.fields.resolutiondate = resolutionDate; } } // resolution date ends
Eliminate all user dimensions for GDPR compliance
You may disable data analytics from the user perspective who created or worked on the issues by eliminating data in dimensions Assignee, Reporter, Transition Author and Logged by. These dimensions will remain in the flex.bi cube but all metrics will show up for the (unassigned) or (none) user.
issue.fields.assignee=null; //eliminate assignee issue.fields.reporter=null; //elimenate reporter for (i=0; i<issue.changelog.histories.length;i++) { hist = issue.changelog.histories[i]; hist.author=null; //eliminate transition author for (j=0;j<hist.items.length;j++) { if (hist.items[j].field=="assignee") { //eliminate assignee history hist.items[j].from=null; hist.items[j].to=null; } }; }; //eliminate logged by if (issue.fields.worklog) { issue.fields.worklog.worklogs.forEach(function(worklogitem){ if (worklogitem.author) { worklogitem.author=null; } }) }
Please contact flex.bi support if you need help to write a custom JavaScript code for your specific needs.