Create issue on Epic at Epic creation

Hi All, 

Im having trouble trying to create an issue at epic creation screen with cascading select: 

Currently what im doing is: 

1) Check cascading select option 

2) if match, clone issue by linking into the new project and issue type (Aligned to the cacasding select)

3) Get issue key of linked issue of the clone and set Epic link field

4) Remove linked issue

 

im currently having issues with 3 and 4

Im sure there is a better way to do this, any help is much appreciated. 

Here is the code i currently have: 

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.UpdateIssueRequest

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('CB-7474')

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

def epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');

MutableIssue epic = ComponentAccessor.getIssueManager().getIssueObject('CASE-17')

issue.setCustomFieldValue(epicLink, epic);

ComponentAccessor.getIssueManager().updateIssue(
            ComponentAccessor.getJiraAuthenticationContext().getUser()
            , issue
            , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build()
    )

Which currently links the epic.

Many thanks ,

Pon

1 answer

1 accepted

0 votes
Accepted answer

For anyone:

 

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
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager

//MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject('CASE-54')
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

/*******************************Customer Field Values*******************************/

String fName = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10004));
String lName = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10005));
String CID = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10000));
def subtaskVal = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(13001));
String fOption = subtaskVal.get(null)
String sOption = subtaskVal.get("1")


def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();
UserManager userManager = ComponentAccessor.getUserManager();

        inputParameters
                  .setProjectId(10600) // Test Enviroment
                  .setIssueTypeId("12106")
                  .setReporterId(currentUser.name)
                  .setSummary(summaryName)
                  .setAssigneeId(currentUser.name)
                  .addCustomFieldValue("customfield_10000", customerID)
                  .addCustomFieldValue("customfield_13002", issue.key)
                  .addCustomFieldValue("customfield_10004", firstName)
                  .addCustomFieldValue("customfield_10005", lastName)
                  .addCustomFieldValue("customfield_13012", '13712');

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

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


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Statuspage

How do your teams prepare for really high (planned) traffic days like Cyber Monday?

Hi there! Shannon from Statuspage here.  👋  With Cyber Monday quickly approaching, we're looking to hear from Atlassian customers – specifically from teams who touch incident response li...

33 views 0 4
Join discussion

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