Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically create a story on Epic Transition ScriptRunner

Shawn Danisa March 20, 2018

I would like to automatically create a Story when an Epic is created.

The following also needs to happen:

  • The Story should have the same summary as the Epic
  • The Story should be linked to the Epic

I am using Script Runner

1 answer

0 votes
Nisha Hajamohideen
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.
March 20, 2018

Hello,

On the Create transition on the Epic Workflow, add a post function.

As you are using script runner, Select Scripted post function and select Clones an issue, and links

This is will you automatically create a linked issue.

For the story to have the same summary as epic:

In the Additional issue actions box add issue.summary = sourceIssue.summary

Maitrey Patel
Community Champion
July 23, 2019

Come on @Nisha Hajamohideen , Shwan is asking to set the epic link, not the linking issue. 

@Shawn DanisaYou need to add a custom script which will link your story to the epic.

Shawn Danisa July 31, 2019

@Nisha Hajamohideen  I did that. However, this feature is limited to "Issue Linking" dependency.  I would like to automatically populate the Epic Link on the story with the Epic (Source) Key

 

@Maitrey Patel : This the script I tried. Created a custom listener to be executed on Issue Create.  However, I didnt get any joy.  Please see my script below:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

// func
def linkIssueToEpic(MutableIssue issue, Issue epicIssue, ApplicationUser user)
{
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def epicLinkField = customFieldManager.getCustomFieldObjects(issue).find { it.name == 'Epic Link' }
issue.setCustomFieldValue(epicLinkField, epicIssue)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Maitrey Patel
Community Champion
July 31, 2019

Hi @Shawn Danisa,

You can achieve this using following script in post function:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.ImportUtils
import com.atlassian.crowd.embedded.api.User;
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def sourceIssue = issue

def epicIssue = sourceIssue
def epicLink = customFieldManager.getCustomFieldObjectByName("Epic Link")



def projectMgr = ComponentAccessor.getProjectManager()
def PROJECT_KEY_TO = "<<DESTINATION PROJECT KEY>>"
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey(PROJECT_KEY_TO)
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issueFactory = ComponentAccessor.getIssueFactory()
def newIssue = issueFactory.cloneIssue(epicIssue)
newIssue.setSummary ("New Story " + epicIssue.summary)
newIssue.setIssueTypeId("3") //3 == TASK - SET ACCORDINGLY  6 for STORY
newIssue.assignee = ComponentAccessor.getUserUtil().getUserByKey("user.name") //Set assignee if you want.

// set the project and any field you want to have a different value
newIssue.setProjectObject(projectTo)

Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)

// Following code is used to link task and epic. with 10630 as is implemented by.
epicLink.updateValue(null, newIssue, new ModifiedValue(newIssue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())
def linkMgr = ComponentAccessor.getIssueLinkManager()
linkMgr.createIssueLink(newIssue.getId(), epicIssue.getId(), 10630, 1, user);
log.info "Issue ${newIssue?.key} cloned to project ${projectTo.key}"

Shawn Danisa August 5, 2019

@Maitrey Patel Thanks for this. it works. It has minor glitch though. it creates extra 24 issues. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events