How to create new Issue in Jira Plugin ?

Albert Cameron September 27, 2021

I found this method :

 

ComponentAccessor.getIssueManager().createIssueObject(user, issue);

 whereas issue is the issue to be created.

So I have problems to create this issue, because Issue and MutableIssue are both interfaces.

You could do 

MutableIssue issueNew = new MutableIssue{...} // implement about 100 Methods :( 

The other way would be with a map .

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Map<String,Object> map = new HashMap<>();
map.put("Summary","My Summary");
// and all the other fields..
Issue createdIssue = ComponentAccessor.getIssueManager().createIssueObject(user,map);

 I am not happy with all these approaches. For example I do not exactly know what key to put in the map. Is it the same as the label you see next to the fields in the ticket ?

1 answer

1 accepted

1 vote
Answer accepted
Juan José Marchal Gómez
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 27, 2021

Hello @Albert Cameron 

you can try with issueFactory

 

import com.atlassian.jira.component.ComponentAccessor

def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserUtil()

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

MutableIssue newissue
newissue = issueFactory.getIssue()

//set values
newissue.setProjectObject(issue.projectObject)
newissue.setIssueTypeId(issue.getIssueTypeId())
newissue.setSummary(issue.summary)
newissue.setDescription(issue.getDescription())
newissue.reporter = issue.getReporter()


def newIssueCreated = issueManager.createIssueObject(currentUserObj, newissue)

 

I hope it helps.

 

Best regards.

Albert Cameron September 27, 2021
IssueInputParameters issueIP = build.getIssueIP();

final IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueIP);

 

Yeah thanks.

There is also a class IssueInputParameters. Which also is usefull for setting CustomFields.

Juan José Marchal Gómez
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 27, 2021

Hello  @Albert Cameron ,

Correct. You can use also IssueInputParamenters.

 Best regards.

Albert Cameron September 27, 2021

If using issueFactory. Is there also a way to add customFields ?

Juan José Marchal Gómez
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 27, 2021

Yes, there is.

After creating the issue, this new issue is a "normal mutable Issue".

So you can use the typical way to update it. 

For example this.

https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-using-a-listener

Best regards.

Suggest an answer

Log in or Sign up to answer