Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,886
Community Members
 
Community Events
168
Community Groups

Smart Values Condition With Lookup Index

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?

 

1 answer

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events