Inherit fields from epic to epic-linked user story

Deleted user September 4, 2017

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

2 votes
Deleted user October 22, 2017

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);
}
}
1 vote
Gsep Support December 7, 2017

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

Deleted user December 20, 2017

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

0 votes
MoroSystems Support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2017

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.

Deleted user October 2, 2017

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


}
Christopher Kelley May 5, 2021

Is there a means to do the exact opposite? Take all of the child Stories and their Fix Version values and "roll-up" these and set the value of the Epic's Fix Version field?

If the children have a fix version value of:

Issue 1: AA

Issue 2: CC

Issue 3: DD, FF

Then the parent Epic would have a fix version of:

AA, CC, DD, FF

This is basically the "roll-up" function of Portfolio. However, roll-up does not actually write the field (which is unfortunate). I want the stories to be tied to releases and this to drive what Epics show for Fix Version as Epics can and do span releases in my universe.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events