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

0 vote
Vasiliy Zverev Community Champion Jun 20, 2016

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
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