How to paste Epic summary, into titles of it's linked issue/subtasks?

Seth Bennett September 8, 2022

I have a project built around publishing. Each Epic will require the same steps (cover, blurb, tag-line, etc.), so I am already automatically generating an Issue with these subtasks. For example:

Book 1 (Epic)

Format this book (issue)

pdf version (subtask)

mobi version (subtask)

epub version (subtask)

The problem is that once multiple books are in the project, that's going to be a lot of issues/subtasks with identical names. In order to fix this, I'm writing a script to add the title (in this case, "book 1"), to the summaries of the corresponding issue / subtasks. So, the end result should look like this: 

Book 1 (Epic)

Format this book: Book 1 (issue)

pdf version: Book 1 (subtask)

mobi version: Book 1 (subtask)

epub version: Book 1 (subtask)

I'm close, but the "setSummary()" command at the end of this script isn't running, despite my successfully logging the necessary id's and summaries to make sure they're there.

I'm current running this code as a Post-Function: Any thoughts? 

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink;

if(issue.issueType.name == 'Epic'){

// Get Target Epic
IssueManager im = ComponentAccessor.getIssueManager();

def issueSummary = issue.getSummary();
def projectTitle = issueSummary.minus("Publish ");

String results = "";
def valid = false;
def output = "";

// Filter through all the Epic's related issues / subtasks
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
    for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
        IssueLink issueLink = (IssueLink) outIterator.next();

        // Create the new issue / subtask string (NewString)
        def linkedIssue = issueLink.getDestinationObject();
        String type = linkedIssue.getIssueType().getName();
        String NewString = type + ": " + projectTitle;

        // Assign the new string to that issue / sub-task's title (CurrentIssueId)
        def CurrentIssueId = linkedIssue.getId();
        MutableIssue CurrentTask = im.getIssueObject(CurrentIssueId);

        // HOW TO APPLY THE NEW SUMMARY TO THE DB?!
        MutableIssue TempIssue = im.getIssueObject(CurrentIssueId);
        TempIssue.setSummary(NewString);
    }
}

1 answer

1 accepted

4 votes
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2022

Hi @Seth Bennett 

 

Have you try to use updateIssue function from IssueManager ?

https://docs.atlassian.com/software/jira/docs/api/7.3.2/com/atlassian/jira/issue/IssueManager.html#updateIssue-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.issue.MutableIssue-com.atlassian.jira.event.type.EventDispatchOption-boolean-

 

updateIssue(ApplicationUser user, MutableIssue issue, EventDispatchOption eventDispatchOption, boolean sendMail)

 

It should be something like this

 

updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),  TempIssue, EventDispatchOption.ISSUE_UPDATED, false)

 

Do not forget to import

 

com.atlassian.jira.event.type.EventDispatchOption

I would have try to use automation for JIRA instead to achieve that with one automation/Task that create the Task and SubTask trigger when an Epic is created.

Regards

Seth Bennett September 8, 2022

Oh, interesting!

It applied those changes to the database, but I had to re-index the server for those changes to show up. 

Just need a way to re-index from the console, and I should be off to the races :)

Suggest an answer

Log in or Sign up to answer