Groovy script for linking Epic to Story using Epic Link

Hi,

I am using GH 6.1.5.

Problem -

I am auto creating Story when a Epic is created using the script runner. The Story so created can have links of type defined in "Issue Linking". But I need it to be the containment relationship using "Epic Link".

How do we acheive this?

1. Aks the script runner to enhance.

2. Write own groovy script.

I am looking at option 2, and following fails to update in Script console, (I am a beginner) -

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();

MutableIssue storyIssue = issueManager.getIssueObject("Proj-10");

CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();

CustomField cf = cfManager.getCustomFieldObjectByName('Epic Link');

cf.getCustomFieldType().updateValue(cf,storyIssue, 'Proj-1');

Kindly help me with corrections/options to acheive this.

Thanks,

Vijai

1 answer

1 accepted

This widget could not be displayed.

If you are still looking for a solution, I assume you know the key to the epic in your script... you should be able to do something like this, this will also link up the Epic/Story in the Agile board.

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;
import com.atlassian.jira.issue.IssueManager;

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

CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
Issue epic = issueManager.getIssue(epicKey); // epicKey is passed into your script

if(epic)
{
	issue.setCustomFieldValue(epicLink, epic);	// issue is the newly created story
}

It don't works in JIRA 6.3.15....

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 Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

578 views 25 15
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