Forums

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

Create a new linked issue but new issue ID is null

Mouna Hammoudi
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.
September 20, 2023

I would like to create a new linked issue of type feature for a super feature issue. Here is my code: 

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())

        }

}

I am using this code block to create a new issue 

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()

then I am using this linke to assign the new issue as a linkedissue:

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

The function CreateIssueLink is helping assign the new issue as a linked issue. Here is the API I am using:

Capture.PNG

The problem is that I get a null pointer exception because newIssue.getId() is null but I cannot assign an ID myselt to the new issue. How can I get the ID and have it automatically generated by Jira so I can avoid the nullpointerexception?

1 answer

0 votes
Mohamed Benziane
Community Champion
September 25, 2023

Suggest an answer

Log in or Sign up to answer