Inherit fields from epic to epic-linked user story

Hi,
is it possible to inherit fields from Epic Story to all epic-linked issues.
For example I want to inherit the field "Affects Version/s" which is a standard jira field from an epic to all it's epic-linked user storys.

I also want to inherit custom field values.

Does anybody offer a solution about this?
Is it possible to cover this with Script Runner?

Thanks,
Michael

3 answers

Allright, I got it. Here is my solution:

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.util.ImportUtils


CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()

// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {

// Get Custom Field as string (Epic Link)
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

// Get Custom Field Value as String
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
String EpicName = issue.getCustomFieldValue(epicLink);

if(EpicName){
// Get Epic from Issue
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue

// Get Fix Version from Epic
def currentValue = epicIssue.getFixVersions()

// Set Fix Version to Story
issue.setFixVersions(currentValue);
}
}

Yes, I think the appropriate solution is to use Script Runner's post function.

  • you will add postfunction to initial transition on workflows which handle issues created "for epic". Postfunction is called Script Post-Function
  • then you will implement a script which will:
    • check whether epic is connected to the created issue, you can check project or issue type of the issue too (you might need to copy values between fields only for few projects and issue types)
    • get the Epic issue (Epic Link custom field)
    • copy the value of epic issue's field to the new issue

You will have to play with it little bit to find out what is the type of value returned for Epic Link custom field etc, but it should work.

Hi thanks for your answer.

Can you help furthermore me with this script? I started but got stuck because I don't know how to copy a field from the linked epic to set it to the user story...

So far I got this:

I got the Epic Issue "Epic", but how can I get the field "Fix Versions" to set it to the User Story?

Thanks again for answering!

Michael

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()

// Check if Issue Type is Story
if (issue.getIssueType().getName() == "Story" ) {

// Get Custom Field (Epic Link)
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');

// Get Content of Custom Field (Epic Name)
String EpicName = issue.getCustomFieldValue(epicLink);

// Get the Epic by name
Issue Epic = issueManager.getIssueObject(EpicName);

// get content of the epic (field Fix Versions)

// Set Field (Fix Versions) from Epic Story to User Story


}

Hello Michael,

Could you please modify above script further for below Scenario:

Create a user story, update a Epic Link ==> Fix Version should be copied from Epic to User Story.

I want to use this with Script Listener, Issue updated Event.

It would be helpful for me and community users.

Thanks in advance.

Suresh

Hi Suresh,

yes that would be nice, I would like to have this feature too :)

Does anyone can offer a solution for this?

 

Thanks,

Michael

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,798 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot