How to create a comment with only the first 10 issues in it

Mark Taranenko December 13, 2024

Hi everybody!
I am trying to create a table using JIRA Automation in the comments to an issue. Basically when an issue is created it should add to the comments a table with related issue using a JIRA query (Lookup Issues).

When I pass this as a comment:
The host "{{issue.customfield_xxxxx}}" was seen in these tickets in the past 30 days: | Key | Field_1 | Field_2 | Field_3 | Field_4 | {{#lookupIssues}} | {{key}} | {{fields.customfield_xxxx}} | {{fields.customfield_xxxx}} | {{fields.customfield_xxxxx}} | {{fields.customfield_xxx}} | {{/lookupIssues}}

It tries to display all issues (using the default limit of up to 100) and the maximum characters limit is exceeded, so the comment can't be added.

How can I limit the table only to the first 10 issues?

2 answers

1 accepted

5 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 14, 2024

Hi @Mark Taranenko -- Welcome to the Atlassian Community!

JQL is not an SQL, and thus it does not have features to return a specific number of issues.  There may be marketplace addons to JQL which provide this capability, although I have not used any of them.

For the scenario you describe, I know three ways to get a specific number of results (e.g., 10 issues) from the Lookup Issues  action results.  I have listed them in level of complexity / effort.

1) Hard-coding

The results of the Lookup Issues action are a list, and so the get() function may return a specific item.  To return the first 10, use a series of get() calls, where the first issue's index is 0 and the tenth is 9:

{{#lookupIssues.get(0)}}
| {{key}} | {{customfield1}} | {{customfield2}} |
{{/}}
{{#lookupIssues.get(1)}}
| {{key}} | {{customfield1}} | {{customfield2}} |
{{/}}

...

{{#lookupIssues.get(9)}}
| {{key}} | {{customfield1}} | {{customfield2}} |
{{/}}

To prevent errors when there are fewer than 10 issues found, conditional logic may be used to test for the presence of each item.  And, remember to add an ORDER BY clause to your JQL to get consistent results.

 

2) REST API call limiting the results size with maxResults

Automation rules use the REST API to perform many of their actions, including Lookup Issues.  Rather than using that action, a rule could call the REST API endpoint for an issue search with JQL and pass the maxResults parameter.  That could be set to 10 to return exactly what is needed.  Calling the endpoint is done using the Send Web Request action.  Here is some information if you want to try this technique:

how-to article for calling a REST API from a rule: https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828

the REST API endpoint for issue search with JQL: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-jql-get

 

3) Dynamic list searching

A more complicated method is to expand the Lookup Issues results into a created variable, including the {{index}} as the list is iterated.  Then use a dynamic regular expression to search the list with the match() function and return the final list.

To learn more about this method, please study this article: https://community.atlassian.com/t5/Automation-articles/Automation-concepts-Dynamic-searches-within-a-list/ba-p/2834235

 

Kind regards,
Bill

Mark Taranenko December 14, 2024

Thank you, Bill!
The first variant was exactly what I needed!
Good to now about other solutions as well

Like Bill Sheboy likes this
2 votes
Dave Liao
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2024

Instead of limiting the results to an arbitrary value - 10 - consider refining your Lookup Issues action to search for a tighter query? For example, issues created within the last 3 days. (Yes, that’s arbitrary too 😂 )

Can you share how your Lookup Issues action is configured?

Mark Taranenko December 14, 2024

It has a JQL that searches for tickets with the same custom_field value in a project for the last 30 days. I can't change it to 3 days, cause the whole purpose of this automation is to retrieve related tickets from the past month

Like Dave Liao likes this
Dave Liao
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 14, 2024

Got it!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events