Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,504,194
Community Members
 
Community Events
180
Community Groups

How to create new Issue in Jira Plugin ?

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

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.

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.

Hello  @Albert Cameron ,

Correct. You can use also IssueInputParamenters.

 Best regards.

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

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