---
title: "Create custom JQL functions for nested issue reporting"
canonical: "https://support.appfire.com/space/PSJ/15482087/Create%20custom%20JQL%20functions%20for%20nested%20issue%20reporting"
format: markdown
---
> Macro (aura-html)


See the step-by-step coding process in this detailed walkthrough:

`<iframe width="560" height="315" src="https://www.youtube.com/embed/sjNRM6X6PTs" frameborder="0" allowfullscreen></iframe>`

### Script

```
string [] tasks;
string [] stories;
string [] epics = selectIssues("issueType = 'Epic' AND project = " + argv[0]);
for(string e in epics) {
    string [] stry = allLinkedIssues(e, "Epic-Story Link");
    for(string s in stry) {
        string [] tsk = allLinkedIssues(s, "jira_subtask_link", 1);
        tasks += tsk;
    }
    stories += stry;
}
string [] results;
results = arrayUnion(epics, stories);
results = arrayUnion(results, tasks);
return results;
```

## Implementation steps

1. Create the SIL script using the code provided above.
2. Customize the script parameters if needed:
  - Modify the epic selection criteria in the `selectIssues` function.
  - Adjust link types if your project uses different linking relationships.
3. Save the script as `jqlnestedsearch.sil` (or your preferred name).
4. Use the script in JQL queries as shown in the example below.

## Example usage

This JQL query returns all epics, stories, and subtasks from project TEST following the complete hierarchy structure.

```
key in silJQLList("jqlnestedsearch.sil", "TEST")
```

You can combine this with additional JQL filters:

```
key in silJQLList("jqlnestedsearch.sil", "TEST") AND created >= -7d
```

This second example returns the same hierarchical results, but only for issues created in the last seven days.