Hi there,
I have been having some issues creating issuelinks from newly cloned issues, I will insert my script for reference
The problem comes when I try issueLinkManager.createIssueLink() if I use the clonedissue.id first then the link wont write and I get a nullpointerexception, but if I put the clonedissue.id second then it will write and the script works fine but my link is obviously the wrong way round.
any ideas as to why this is happening and how I can fix it?
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
IssueService issueService = ComponentAccessor.getIssueService()
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager()
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey("***")
def projSubTask = issueManager.getIssueObject("******")
def issueQuery = jqlQueryParser.parseQuery("Project = *** AND issuetype = story")
def issueResults = searchProvider.search(issueQuery, user, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${issueResults.total}")
issueResults.getIssues().each { documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
def subtasks = issue.getSubTaskObjects()
def toClone = issueFactory.cloneIssueWithAllFields(issue)
def ClonedProject = toClone.setProjectObject(projectTo)
def Cloned = issueManager.createIssueObject(user, toClone)
def clonedIssue = issueManager.getIssueObject(Cloned.key)
issueLinkManager.createIssueLink(clonedIssue.id as long, projSubTask.id as long, 10304 as long, 1, user )
if (subtasks) {
subtasks.each { subTask ->
def subTaskParent = Cloned
def subTaskToClone = issueFactory.cloneIssueWithAllFields(subTask)
def subTaskProject = subTaskToClone.setProjectObject(projectTo)
def subTaskCloned = issueManager.createIssueObject(user, subTaskToClone)
subTaskManager.createSubTaskIssueLink(subTaskParent, subTaskCloned, user)
}
}
}
This is strange, seems to be only doing this if I try to link it to a particular issue, I have tried with several other issues and it works fine. this is a dev instance though so it could be something to do with the environment.
Hi @Will C ,
Your script has been working fine with me. I tried linking both ways with blocks linking. I do not think I have changed muched, I added some logs to check the execution, maybe you could provide some logs ?
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
IssueService issueService = ComponentAccessor.getIssueService()
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager()
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def projectTo = ComponentAccessor.getProjectManager().getProjectByCurrentKey("BPIW")
def projSubTask = issueManager.getIssueByCurrentKey("IBT-26")
def issueQuery = jqlQueryParser.parseQuery("key = IBT-23")
def issueResults = searchProvider.search(issueQuery, user, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${issueResults.total}")
issueResults.getIssues().each { documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
log.error("issue: " + issue)
def subtasks = issue.getSubTaskObjects()
def toClone = issueFactory.cloneIssueWithAllFields(issue)
log.error("toClone : " + toClone)
toClone.setProjectObject(projectTo)
def Cloned = issueManager.createIssueObject(user, toClone)
log.error("Cloned : " + Cloned)
def clonedIssue = issueManager.getIssueObject(Cloned.key)
log.error("clonedIssue : " + clonedIssue)
issueLinkManager.createIssueLink(clonedIssue.id as long, projSubTask.id as long, 10000 as long, 1, user )
if (subtasks) {
subtasks.each { subTask ->
def subTaskParent = Cloned
def subTaskToClone = issueFactory.cloneIssueWithAllFields(subTask)
def subTaskProject = subTaskToClone.setProjectObject(projectTo)
def subTaskCloned = issueManager.createIssueObject(user, subTaskToClone)
subTaskManager.createSubTaskIssueLink(subTaskParent, subTaskCloned, user)
}
}
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antoine, thanks for the reply, I've tried with some logs, it creates the first issue and then fails, Im sure its failing at the point of creating the issuelink as if you take the createissuelink out then it runs fine.
I will experiment with different link types and different issues to see if its that? although I would have thought this should run with any?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is strange, seems to be only doing this if I try to link it to a particular issue, I have tried with several other issues and it works fine. this is a dev instance though so it could be something to do with the environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.