How to create an Epic link programmatically in an issue?

Thushara Wimalasena October 6, 2017

 

I have developed an add-on which has the capability to connect to our remote application and import security vulnerabilities into Jira server as Jira issues.

During the import process (programmatically), I create an issue as per given configurations and one of the configuration is Epic link. So when I create issues, Epic link should be populated with them. Anyway I managed to create issues with given all the configurations (IssueType, Assingee, reporter, Labels, Description etc.) except Epic link. Epic link is not get set.

I used the following code snippet to create issues and set Epic Link but it is never succeeded.

One thing I noticed is that all the String type data fields are get set to the issue objects successfully but when I try to set Object type data field, it is not get set to the issue object. Epic Link is a Object data type.

 

// First Create an MutableIssue
MutableIssue newJIRAIssue = ComponentAccessor.getIssueFactory().getIssue();

// Then we create an Custom field for Epic link
CustomFieldManager cfMgr = ComponentAccessor.getCustomFieldManager();
CustomField epicCustomField = cfMgr.getCustomFieldObjectByName(“EPIC LINK”);

// Then we get the existing Epic issue
MutableIssue epicIssue = ComponentAccessor.getIssueManager().getIssueObject(“Epic-234”);

// Then we set the Epic link to the newly created MutableIssue
newJIRAIssue.setCustomFieldValue(epicCustomField, epicIssue);

try {
       // We try to create the issue with all the setting including Epic link. But we get always get NoSuchMethodError exception in JIRA 7.x.x

returnIssue = issueManager.createIssueObject(user, newJIRAIssue);

       } catch (java.lang.NoSuchMethodError e) {

           //Then we try reflection as following to create the issue. It creates the issue successfully but the given Epic link has been not set to the issue

Class<?> givenObjectClass = issueManager.getClass();

                for (Method m : givenObjectClass.getMethods()) {
                     if (m.getName().equals("createIssueObject")// We also validate parameter list here to determine exact overloaded method) {

                        objectReturned = m.invoke(givenObject, givenParameters);
                        return objectReturned
                      }
                }
       }

 

0 answers

Suggest an answer

Log in or Sign up to answer