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
log = Category.getInstance("com.onresolve.jira.groovy.CreateDependentIssue")
issueMgr = ComponentManager.getInstance().getIssueManager()
projectMgr = ComponentManager.getInstance().getProjectManager()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
issueFactory = ComponentManager.getInstance().getIssueFactory()
newissue = issueFactory.getIssue()
newissue.setSummary (issue.summary)
newissue.setProject (issue.project)
newissue.setIssueTypeId("6") //6 == Story
newissue.description = issue.description
newissue.reporter = issue.getReporter()
newissue.assignee = issue.getAssignee()
params = ["issue":newissue]
subTask = issueMgr.createIssue(currentUserObj, params)
println subTask.get("key")
linkMgr = ComponentManager.getInstance().getIssueLinkManager()
linkMgr.createIssueLink (newissue.id, issue.id, Long.parseLong("10300"),Long.valueOf(1), currentUserObj)
Like this:
Like Loading...
Related
Code for the version 8:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Category
def log = Category.getInstance(“com.onresolve.jira.groovy.CreateDependentIssue”)
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.getProjectManager()
def linkManager = ComponentAccessor.getIssueLinkManager()
def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def issueFactory = ComponentAccessor.getIssueFactory()
// create new issue from factory
MutableIssue newissue
newissue = issueFactory.getIssue()
//set values
newissue.setProjectObject(issue.projectObject)
newissue.setIssueTypeId(issue.getIssueTypeId())
newissue.setSummary(“[” + it.toString() + “] ” + issue.summary)
newissue.setDescription(issue.getDescription())
newissue.reporter = issue.getReporter()
newissue.assignee = issue.getAssignee()
//create actual issue
def subTask = issueManager.createIssueObject(currentUserObj, newissue)
//link the issue
linkManager.createIssueLink (newissue.id, issue.id, Long.parseLong(“10300”),Long.valueOf(1), currentUserObj)
LikeLiked by 1 person
Another example using the canned script built-in to clone (by Scriptrunner):
https://library.adaptavist.com/entity/copy-an-issue-to-a-new-project-and-link-to-the-original
LikeLiked by 1 person