How to copy values from Epic to Story?

I would like to try the Behaviours add-on to copy value from a text field from epic to story. We have a script for post function but some workflows are to big and it makes the maintenance awkward.

We are using:

  • JIRA server v7.2.7
  • Adaptavist ScriptRunner for JIRA v4.3.19

our script for post function:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.managers.DefaultIssueManager;
import com.atlassian.jira.issue.IssueManager;
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager()
CustomField el = cfm.getCustomFieldObject('customfield_11571')
CustomField cpi = cfm.getCustomFieldObject('customfield_11095')
IssueManager im = ComponentAccessor.getIssueManager()
issue.setCustomFieldValue(cpi, im.getIssueByCurrentKey((String)issue.getCustomFieldValue(el)).getCustomFieldValue(cpi))

 I tried to use the script from CGM, but I get an error message:

https://community.atlassian.com/t5/Jira-questions/Copy-values-from-Epic-to-Story-on-creation/qaq-p/214566#U710980

Can you help me?

Best regards,
Tatiana

1 answer

This widget could not be displayed.

Hey,

In order to copy value for epic to all the story under it-(post function)

Try this:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

MutableIssue issue = issue
if (issue.getIssueType().name == "Epic"){
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
List<IssueLink> outwardLinks = issueLinkManager.getOutwardLinks(issue.getId())
CustomField cf1 = customFieldManager.getCustomFieldObjectByName("cutsomfieldname")
def cfvalue = issue.getCustomFieldValue(cf1)

List<Issue> issueinepic = new ArrayList<Issue>();

for(int i=0;i<outwardLinks.size();i++){
if(outwardLinks[i].getIssueLinkType().getName()=="Epic-Story Link"){
def destObject = outwardLinks[i].getDestinationObject()
def changeHolder = new DefaultIssueChangeHolder();
cf1.updateValue(null, destObject, new ModifiedValue(destObject.getCustomFieldValue(cf1),cfvalue), changeHolder);
issue.store()

}
}
}

Thank you for the prompt response.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

209 views 1 3
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