Getting a field value of an epic from an associated task

This is what I am trying to accomplish: I have timecard charge numbers as a custom field define for all our epics. I am using arsenal dataplane to create a report for all team members that show the time they logged on tasks and subtasks. I would like to show in that report the charge code for the epic associated with the task. If you didn't follow here's another explanation of what I am trying to do: simply show the value from an epic custom field in a report that shows task information.

I think I can do this with scriptrunner custom field for a task that finds the parent epic and reads the charge number value. I would then have that information in a custom field associated with task that I can use for reports. I have created a custom field in scriptrunner for the task but can't figure out the script. Any help on writing the script would be greatly appreciated. If you don't use scriptrunner but know how to do this from Java API plugin I would love to see that code because that might be good enough for showing me how to do it. Thanks!

1 answer

1 accepted

This widget could not be displayed.
Alexey Matveev Community Champion Dec 31, 2017

The code would be like this

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
Issue epic = issue.getCustomFieldValue(epicLink) as Issue;
CustomField cs = customFieldManager.getCustomFieldObjectByName("customFieldName");
return epic.getCustomFieldValue(cs)

This worked beautifully! Thank you. Except. This worked for just the tasks. Is there some code that could be added such that if this is a subtask that it moves to the task and then finds the custom field.

Figured out something that works for subtasks and tasks. Again, thanks for help! See code below:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');

if (issue.isSubTask()){
issue = issue.getParentObject();
}

Issue epic = issue.getCustomFieldValue(epicLink) as Issue;
CustomField cs = customFieldManager.getCustomFieldObjectByName("Charge Code");
return epic.getCustomFieldValue(cs)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

97 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you