Forums

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

Scriptrunner Clone Subtask and attach it to parent that already exists

Will C
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 2, 2020

I am currently trying to clone a subtask and  then with the new cloned issue attach it to a parent that already exists, here is my script 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Logger
import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def subTaskToCopy = issueManager.getIssueObject("EN-222")
def PSDCF = customFieldManager.getCustomFieldObjectsByName("Planned Start Date")[0]
def PEDCF = customFieldManager.getCustomFieldObjectsByName("Planned End Date")[0]
def list = ['EN-35', 'EN-32', 'EN-27']

list.each {workPackage ->
def issue = issueManager.getIssueObject(workPackage)
log.debug (issue.getSummary())
def issuePSDCFV = issue.getCustomFieldValue(PSDCF)
def issuePEDCFV = issue.getCustomFieldValue(PEDCF)
def newSubTaskCloner = issueFactory.cloneIssueWithAllFields(subTaskToCopy)
newSubTaskCloner.setCustomFieldValue(PSDCF, issuePSDCFV)
newSubTaskCloner.setCustomFieldValue(PEDCF, issuePSDCFV)
def newSubTaskCreate = issueManager.createIssueObject(user, newSubTaskCloner)
subTaskManager.createSubTaskIssueLink(issue, newSubTaskCreate, user)
}

This returns this error 

java.lang.NullPointerException at com.atlassian.jira.issue.link.DefaultIssueLinkManager.getIssueLink(DefaultIssueLinkManager.java:381) at com.atlassian.jira.issue.link.DefaultIssueLinkManager.createIssueLink(DefaultIssueLinkManager.java:89) at com.atlassian.jira.config.DefaultSubTaskManager.createSubTaskIssueLink(DefaultSubTaskManager.java:443) at com.atlassian.jira.config.SubTaskManager$createSubTaskIssueLink.call(Unknown Source) at Script402$_run_closure1.doCall(Script402.groovy:34) at Script402.run(Script402.groovy:23)

I have checked all variables have a value at point of creating the parent link, which they do.

I think the issue is with the parent issue that I am passing accross, what method should I be using to get the parent issue? bearing in mind that the parent existed before this script, as issueManager.getIssueObject() doesn't seem to be working. 

1 answer

0 votes
Will C
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 24, 2020

anybody having issues with this?

I have used subtaskManager.createSubtaskIssueLink() before, but when used before the parent issue was created in that script too.

Suggest an answer

Log in or Sign up to answer