It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted

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 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,099 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you