issuesInEpics/epicsOf JQL functions aren't producing the expected results

Problem

Using the issuesInEpics or epicsOf JQL function returns no issues, or fewer than expected.

Solution

This problem is usually the result of there being more than one issue link type with the name Epic-Story Link. This is a known bug that originates from Jira itself, but you can use ScriptRunner to help check for it. Simply run the following two scripts separately in the Script Console and compare their results:

Script One
import com.atlassian.jira.component.ComponentAccessor

// Replace ISSUE-KEY-HERE with the key of any issue that should be appearing in the JQL results
def issue = ComponentAccessor.issueManager.getIssueObject("ISSUE-KEY-HERE")

ComponentAccessor.issueLinkManager.getLinkCollection(
    issue,
    ComponentAccessor.jiraAuthenticationContext.loggedInUser,
    false
).linkTypes.collect {[it.id, it.name]}
Script Two
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager

def iltm = ComponentAccessor.getComponent(IssueLinkTypeManager)

def linkId = iltm.getIssueLinkTypes(false).findByName("Epic-Story Link").id

The first script will show the names and numerical IDs of all the types of links connected to the given issue - this should include one called Epic-Story Link. The second script will show the numerical ID of the first issue link type it finds called Epic-Story Link. If the IDs of these two Epic-Story Link types are not the same, then your Jira instance has the bug.

You can resolve the problem by following these instructions provided by Atlassian. Direct manipulation of the Jira database is required, so be sure to make a backup and consult with your DBA as appropriate.