How do I create a scripted post function that creates a simple ticket

What is the custom scripted post function that creates a simple ticket, copying ONLY 3 fields from the original ticket?  Cloning a ticket will not help me, because it copies everything, and I don't want everything.  I only want the information from 3-4 fields to carry over, and I do not want the issue to be linked.

1 answer

Here is code example:

package IssueCreation

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.util.ErrorCollection

/**
 * Created by VZverev on 10.06.2016.
 */

//Issue issue = null;//only for test purpose

IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();

UserManager userManager = ComponentAccessor.getUserManager();

inputParameters
        .setProjectId(issue.getProjectId())
        .setIssueTypeId("11504")
        .setReporterId(ComponentAccessor.getJiraAuthenticationContext().getUser().getName())
        .setSummary(issue.getSummary())
        .setAssigneeId(userManager.getUserByKey(issue.getAssigneeId()).getName())

ApplicationUser curUser = ComponentAccessor.getJiraAuthenticationContext().getUser();

IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(curUser, inputParameters)

if(!createValidationResult.isValid()){
    ErrorCollection errorCollection = createValidationResult.getErrorCollection();
    return errorCollection.toString()
}
else{
    IssueService.IssueResult createResult = issueService.create(curUser, createValidationResult)
    IssueIndexManager issueIndexManager = ComponentAccessor.getIssueIndexManager();
    issueIndexManager.reIndex(createResult.getIssue())
}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you