在 Jira 中创建新的链接事务,但新事务 ID 为 null

Create a new linked issue but new issue ID is null in Jira

提问人:Mouna Camelia Hammoudi 提问时间:9/20/2023 最后编辑:Mouna Camelia Hammoudi 更新时间:9/21/2023 访问量:17

问:

我想为超级功能问题创建一个新的链接问题。这是我的代码:

void createFeature(Issue issue, List<String> componentList){

    // Issue issue

//def issueManager = ComponentAccessor.issueManager

//def issueFactory = ComponentAccessor.issueFactory

def issueLinkManager = ComponentAccessor.issueLinkManager

//def userManager = ComponentAccessor.userManager

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

def issueFactory = ComponentAccessor.getIssueFactory()

def issueManager = ComponentAccessor.getIssueManager()

def userManager = ComponentAccessor.getUserUtil()

 def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

MutableIssue newIssue= ComponentAccessor.issueFactory.issue

newIssue.setProjectObject(issue.getProjectObject())

newIssue.setSummary("MOUNA CAMELIA")

newIssue.setIssueTypeId("19")

int issueLinkType= 10070

long sequence =1

long newissueTypeID= 19

long myissueID= issue.getId()

 MutableIssue newissue

newissue = issueFactory.getIssue()

//set values

newissue.setProjectObject(issue.projectObject)

newissue.setIssueTypeId("19") 

newissue.setSummary("MOUNA CAMELIA")

newissue.setDescription("MOUNA CAMELIA")

newissue.reporter = issue.getReporter()

def newIssueCreated = issueManager.createIssueObject(currentUserObj, newissue)

newIssue.setDescription(issue.getDescription())

                for(String component: componentList){

                    log.warn("MOUNA CAMELIA component"+ component +" NEW ISSUE "+ newIssue)

                     log.warn("MOUNA CAMELIA Component ====="+ component+"===== myissueID ====="+ myissueID+" =====newissueTypeID ====="+newissueTypeID +" =====issueLinkType ====="+issueLinkType 

                     +" =====sequence ====="+ sequence +" =====authenticationContext.getLoggedInUser() ====="+authenticationContext.getLoggedInUser()+" newIssue.getId() "+newIssue.getId())                

                    issueLinkManager.createIssueLink(myissueID, newIssue.getId(), issueLinkType, sequence, authenticationContext.getLoggedInUser())

        }

}

我正在使用此代码块创建一个新问题

MutableIssue newIssue= ComponentAccessor.issueFactory.issue

newIssue.setProjectObject(issue.getProjectObject())

newIssue.setSummary("MOUNA CAMELIA")

newIssue.setIssueTypeId("19")

int issueLinkType= 10070

long sequence =1

long newissueTypeID= 19

long myissueID= issue.getId()

然后我使用此链接将新问题分配为 linkedissue:

 issueLinkManager.createIssueLink(myissueID, newIssue.getId(), issueLinkType, sequence, authenticationContext.getLoggedInUser())

该函数正在帮助将新问题指定为链接问题。这是我正在使用的 enter image description here API,问题是我得到一个空指针异常,因为是,但我无法为新问题分配 ID mysert。如何获取 ID 并由 Jira 自动生成,从而避免 nullpointerexceptionCreateIssueLinknewIssue.getId()null

nullpointerexception jira-plugin jira-rest-java-api scriptrunner-for-jira

评论


答:

0赞 Mouna Camelia Hammoudi 9/21/2023 #1

缺少以下代码行

def newIssueCreated = issueManager.createIssueObject(currentUserObj, newissue)

然后,我们需要使用该变量作为函数的参数newIssueCreatedCreateIssueLink

long newIssueCreatedID= newIssueCreated.getId()
                 for(String component: componentList){

                     log.warn("MOUNA CAMELIA ===== myissueID ====="+ myissueID+" =====newissueTypeID ====="+newIssueCreated.getId()
                      +" =====issueLinkType ====="+issueLinkType 
                     +" =====sequence ====="+ sequence +" =====authenticationContext.getLoggedInUser() ====="+authenticationContext.getLoggedInUser()
                     +"issuelinkmanager===="+issueLinkManager)                
                     issueLinkManager.createIssueLink(myissueID, newIssueCreatedID, issueLinkType, sequence, authenticationContext.getLoggedInUser())

         }
}