How to copy values from Epic to Story?

Tatiana Jancusova January 24, 2018

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

Suggest an answer

Log in or Sign up to answer
1 vote
Neta Elyakim
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.
January 25, 2018

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()

}
}
}
Gugulethu Mabaso August 23, 2018

Thank you for the prompt response.

TAGS
AUG Leaders

Atlassian Community Events