Request for Javascript example

Hi. We’re tracking a lot of our data (such as Priority, and many custom fields) only on the Epic, but we want to report at the story level. I’m having performance issues, trying to do this through MDX, so I thought I would try using Javascript to create dimensions on import. Could someone post an example of how I would create a field (let’s call it “PriorityOfEpic”) that lives only on Stories, but which is populated with the priority value from the Story’s Epic.

Thanks!

Hi,

Please, find here the javascript code giving the priority name of an epic for the Epic linked issue.

[jira.customfield_epic_priority]
name="Epic priority"
data_type="string"
javascript_code='''
issue.fields.issuelinks.forEach(function(link_item){
	if (link_item.type.inward=="has Epic" && link_item.inwardIssue) {
		issue.fields.customfield_epic_priority=link_item.inwardIssue.fields.priority.name;
		return;
	}
});
'''

The code accesses the JSON representation of an issue, where the epic link is available through the structure as in the attached picture. Please, note that only limited list of fields is available through this structure.

The alternative solution is to create a custom field which gives value only for the epics and use the “update_from_issue_key=“epic_key”” option for this field. This will tell eazyBI to inherit for the child and subtask issues the value from the epic. The advanced settings would look like this:

[jira.customfield_inherit_a_field]
name = "Epic inherited field (IC)"
data_type="string"
dimension = true
update_from_issue_key="epic_key"
javascript_code='''
 if (issue.fields.issuetype.name=="Epic") {
 	issue.fields.customfield_inherit_a_field=issue.fields.customfield_10206;// use your field ID here
 }
'''

This is a better solution also in that it inherits the field (in this case customfield_10206) down to the sub-task level.

Kindly,
Janis eazyBI support

3 Likes