The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Smart Values Condition With Lookup Index

Hagay
September 15, 2022

Hi,

With Jira automation, I'm doing a lookup and I want to use only the first 20 items of the returned JQL. Since JQL does not support something similar to "TOP N", I wanted to use the index property of the lookup.

Note the "if" below:

{{#lookupIssues}}
{{#if(index.lt(20))}}
{{index}} - {{summary}} (by {{assignee.displayName}})
{{/}}
{{/}}

But this doesn't work, without any errors. 

The {{index}} part works as expected (in case I remove the condition).

Can I use the index to get the first items of a lookup result?

 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

3 votes
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 Champions.
September 15, 2022

Hi @Hagay 

Short answer: This may not be possible using {{index}} that way, and there is at least one work-around

Longer answer:

Smart value, list filtering appears to only access the issue fields;  {{index}} is an attribute of the list, not of any of the issues.  And so it cannot be used in the filtering or apparently with functions.  If you believe {{index}} should work this way, I suggest submitting a defect to Atlassian Support.

One possible work-around is to store your lookup issues result in a created variable as a text string, split it by a delimiter, and then use match() with a regular expression to find the first 20 items.

For an example, please see below, and adjust the delimiters, as needed, based upon your issue summary contents (i.e. punctuation characters).

  • action: lookup issues with JQL.  For consistency, I would add an ORDER BY statement to the JQL.
  • action: create a variable to store the consolidated list and their 0-based index
    • name: varLookupData
    • smart value:  Create a text string, delimited by ";index:" at the beginning of each issue.
{{#lookupIssues}};index:{{index}} - {{summary}} (by {{assignee.displayName}}){{/}}
  • action: log the results (or whatever you need) with the results of the first 20 items
{{varLookupData.split(";index").match(":((0|[1-9]|1[0-9]) .*)").substringAfter(" - ")}}

Split the text string on ";index" and leave the starting colon, to create a new list.  The match() function will then find only items beginning with ":0" through ":19".  The final substringAfter removes the index prefix information, leaving only the summary and assignee.

Kind regards,
Bill

0 votes
John Funk
Community Champion
June 20, 2023

Hi @Hagay  - Did you ever try to implement Bill's answer? 

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events