I would like to automatically create a Story when an Epic is created.
The following also needs to happen:
I am using Script Runner
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
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.
@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.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.user.ApplicationUser// funcdef linkIssueToEpic(MutableIssue issue, Issue epicIssue, ApplicationUser user) {def customFieldManager = ComponentAccessor.customFieldManagerdef issueManager = ComponentAccessor.issueManagerdef epicLinkField = customFieldManager.getCustomFieldObjects(issue).find { it.name == 'Epic Link' }issue.setCustomFieldValue(epicLinkField, epicIssue)issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)}
Hi @Shawn Danisa,
You can achieve this using following script in post function:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.util.UserUtilimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.link.IssueLinkimport com.atlassian.jira.util.ImportUtilsimport com.atlassian.crowd.embedded.api.User;import com.opensymphony.workflow.WorkflowContextimport org.apache.log4j.Category
def customFieldManager = ComponentAccessor.getCustomFieldManager()def issueManager = ComponentAccessor.getIssueManager()def sourceIssue = issue
def epicIssue = sourceIssuedef 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 STORYnewIssue.assignee = ComponentAccessor.getUserUtil().getUserByKey("user.name") //Set assignee if you want.// set the project and any field you want to have a different valuenewIssue.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}"
It looks like you're new here. Sign in or register to get started.