Both of these are still printing a comma (, ) at the end of the list. Any idea why??
Hi @Troy Anderson
{{^last}} is evaluated against the original loop, not your filtered output.Because you’re skipping items inside the loop with #if(...), the item you print last usually isn’t the actual last element of the collection. so {{^last}} is still true and you get a trailing comma.
#if(...)
Fix it by making the loop only contain the items you’ll print, then last will work
I am not sure if this will work but you can try something similar below
{{#issue.issuelinks.whereEquals("type.inward","is cloned by").whereStartsWith("issue.key","SCR")}}{{issue.key}} - {{issue.status.name}}{{^last}}, {{/last}}{{/issue.issuelinks.whereEquals("type.inward","is cloned by").whereStartsWith("issue.key","SCR")}}
Yes, and...to the suggestions from @Tuncay Senturk _Snapbytes_ with some adjustments...
For iteration which has filtering, I recommend not worrying about a trailing delimiter such as a comma; the complexity / risk of errors is not worth the trouble.
Instead, always add the delimiter and remove it later with text functions prior to a splitting back into a list. Also, I recommend combining your iterators and conditional filtering. For example:
{{#lookupIssues.issuelinks}}{{#if(and(equals(type.inward, "is cloned by"), inwardIssue.key.startsWith("SCR")))}}{{key}} - {{status.name}},{{/}}{{/}}
{{varFilteredList.substringBeforeLast(",").split(",")}}
Given the number of filters, it may be better to just change the JQL for the lookup action to avoid this complexity.
Finally, please note: once inside of a {{lookupIssues}} iterator, the issue prefix is not used, just the field smart values.
Kind regards,Bill
Thanks @Tuncay Senturk _Snapbytes_. I understand the reason now.
I was not able to get your sample snippet to work. Not finding whereEquals or whereStartsWith as available options. It does not error, though, which is interesting.
Thanks for the tips and suggestions @Bill Sheboy.
Ultimately, this is all going into a single API call to update/overwrite a Confluence page using values from each entry in #lookupIssues and each item's corresponding #issuelinks. I am hamstrung in use of a variable in this situation. There is also no way to group in this manner using standard JQL.
Interestingly, I have needed to use the issue prefix. The following will filter to the 'correct' linked items but will only write a "-" to the log unless I use issue.key and issue.status.name. As well, if I use just "key.startsWith", the conditional returns no items.
The following does write the key and status to the log (without use of the issue prefix), however: ~edited to add the correct screenshot here.
I wonder...
For a given work item, can you write a JQL expression to return the correct work items, and use that to gather them with Lookup Work Items? Perhaps using the linkedIssues() function:
project = SCR AND issue IN linkedIssues("{{triggerIssue.key}}", "is cloned by") ORDER BY key ASC
...adding whatever you need to the JQL. You may need to invert the link type to get the direction you want. And, the project may need multiple-project (or global) scope if they are in different projects because now the actual work items are found rather than just the data from the issuelinks smart value.
That eliminates the need for the list filtering causing complications.
I was testing something similar (see below), but I do not know of a way to access more than one set of work items in subsequent actions. I guess a variable would help with that. I am not sure I could get the grouping right.
Additionally, I am doing a batch run to keep the page updated with a full set of the latest data. No specific triggering action, in other words. I may have to rethink the approach to do exactly what I want to do though.
And now I cannot recreate the issue. REALLY confused...
It looks like you're new here. Sign in or register to get started.