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)
Posted by:.

2 replies on “PostFunction Groovy Script Runner to CLONE issue with different type and Link between

  1. 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)

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s