Struggling to parse distinct sprints from an Automation lookup

Brock Jolet
Contributor
February 28, 2024

I'm trying to create an Automation rule that parses out future sprints based on a lookup. For some reason, using a For each isn't splitting the return into multiple values.

 

The basic idea is this:

  • Lookup issues:
    • project = TEST and sprint in futureSprints()
  • For each:
    • define variable: distinctSprint
    • distinctSprint = {{lookupIssues.sprint.distinct}}
  • If:
    • {{distinctSprint.state}} = future
  • Log sprint details

 

I expect the For each to run once for each unique sprint, but instead, it's running a single time with all of the sprints as one large payload.

I'm still able to find attributes within such as the various states of the sprints, but because they're all running at once I'm unable to affect them separately.

I added a log for ▶ {{state}} {{distinctSprint.id}} ◀ and you'll see in the audit that it's printing all of the states, then all of the IDs.

2024-02-28_15h40_55.png

 

What am I missing? I have a similar rule using this method that has been working for months now and this current rule is making me think the old one is working despite a flaw in design.

1 answer

1 accepted

2 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.
February 28, 2024

Hi @Brock Jolet 

Have any of the issues been in multiple sprints, such as carry-over from prior sprints?

If so, please consider {{lookupIssues.sprint.distinct}} is...

  • grabbing the sprint from each issue in the result set
  • where those could be lists of values for an issue
  • and then performing distinct on the lists of values per issue

For example: 

  • issue 123 was in sprint A
  • issue 456 was in sprint B and C
  • issue 789 was in B

The distinct result will be: A, B, C, B and not what we would hope: A, B, C

The work-around for this scenario is to merge everything first, then split and distinct.  One wrinkle is you want only future sprints, and so the filtering needs to be on "future" state before merging.

So if we first create a variable, named varSprintList with the expression using nested iterators:

{{#lookupIssues}}{{#sprint}}{{#if(equals(state,"future"))}}{{name}},{{/}}{{/}}{{/}}

I purposely left the trailing comma so we know exactly what is in the result text.

Then the distinct list can be found with this:

{{varSprintList.substringBeforeLast(",").split(",").distinct}}

If you need the sprint id values (or multiple attributes), rather than the names, please adjust accordingly.

Kind regards,
Bill

Brock Jolet
Contributor
February 29, 2024

Thanks, @Bill Sheboy .

This is exactly what I needed.

Like Bill Sheboy likes this
Brock Jolet
Contributor
February 29, 2024

Hey @Bill Sheboy ,

I've got it working, but I'm trying to add more functionality. Any idea why checking if the id matches a string doesn't work? I'm able to use state or name just fine. I've also been unable to convert the id to a string.

 

I would expect the following to print the name of the sprint if the id matches:

{{#lookupIssues}}{{#sprint}}{{#if(equals(id,"1239"))}}{{name}},{{/}}{{/}}{{/}}

 

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.
February 29, 2024

Please try using the format() function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#format-input-

Perhaps like this:

{{#lookupIssues}}{{#sprint}}{{#if(equals(id.format("#"),"1239"))}}{{name}},{{/}}{{/}}{{/}}

 

Like Brock Jolet likes this
Brock Jolet
Contributor
February 29, 2024

Perfect!

Like Bill Sheboy likes this

Suggest an answer

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

Atlassian Community Events