IssueFactory.getIssue()创建了一个id == null的问题

时间:2016-06-21 02:10:11

标签: java groovy jira jira-plugin

您好我使用adaptavist scriptrunner创建了一个创建子任务的小脚本:

ApplicationUser user   = // .. obtaining the user
MutableIssue parent = // .. obtaining parent issue
MutableIssue child  = issueFactory.getIssue()

// ... filling child with some data

// here the errors appear:
// workflow error
Issue subtask = issueManager.createIssueObject(user, child)
// null pointer
subTaskManager.createSubTaskIssueLink(parent, child, user)

我试图找出错误的原因,看起来我发现了问题所在: child.getId()返回null。我错过了什么? getIssue()应该返回没有ID的空白问题吗?

Jira版本7.1.7

2 个答案:

答案 0 :(得分:1)

这应该有效:

还有this related question on Atlassian Answers有一些示例代码。

答案 1 :(得分:0)

MutableIssue child  = issueFactory.getIssue()
// issueFactory.getIssue(), returns an instance of MutableIssue, 
// that will be used to set issue data, here issue is not yet created
// in jira yet hence issue id and key will be null here
// ...

Issue subtask = issueManager.createIssueObject(user, child)
// issueManager.createIssueObject(user, child), creates the issue
// in the jira and after execution of this statement, you can retrieve
// issue id and issue key