Get sprint goal for open sprint
Asked by Salim Bouassida:

Hello there,

I am trying to create a Jira automation that send a slack message that contains the sprint goals for two teams.

Initially i had this structure:

When

* scheduled (every 2 weeks)
* JQL: *project = Understand and Sprint in openSprints()*

Create variable

* Smart issue: sprintgoal = {{#issue.customfield_10015}} {{#if(equals (state, "active")) }} {{goal}} {{/}} {{/}}
* (our sprint goal field is linked to customfield_10015)

Slack message

* send {{sprintgoal}}

However, I noticed that it would send 20 + message for each issue that matches that JQL. I then tried to set an if statement checking a smart value "done" has a value, but it still sends the message 20 times.

![Capture d?e?cran 2022-10-18 a? 09.59.17.png](https://community.atlassian.com/t5/image/serverpage/image-id/221292iDBB8EF104A9F0A15/image-size/large?v=v2&px=999 "Capture d?e?cran 2022-10-18 a? 09.59.17.png")

Do you have an idea to pull the Sprint goal for only the first issue in the JQL list?

thanks !


Answers:
author: Curt Holley
body: OK [@Salim Bouassida](/t5/user/viewprofilepage/user-id/4246823) [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)   

I have it working...at least to email, but theory is the same for Slack.

Schedule trigger (no JQL)

Lookup issues action with

```

sprint in openSprints()
```

as the JQL.

Send email/Slack action with:

```


{{lookupIssues.first.sprint.distinct.goal}}?
```

comments: author: Salim Bouassida
body: Hello [@Curt Holley](/t5/user/viewprofilepage/user-id/3527535) ,

This worked perfectly !

I didn't need to create the variable, and used the reference in the slack message only.

Thanks for your help !


author: Sonora Braun
body: Can someone please send exactly what this looks like? Or exactly where you are doing the lookup?

This is not working for me:

I have added in the scheduled JQL

```
sprint in openSprints()


```

and done an "Then" for sending the slack with:

```


{{lookupIssues.first.sprint.distinct.goal}}?
```

![Screenshot 2024-07-17 at 10.34.54?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/336113i4D5093CB78BD9F65/image-size/large?v=v2&px=999 "Screenshot 2024-07-17 at 10.34.54?AM.png")


author: Bill Sheboy
body: Hi [@Sonora Braun](/t5/user/viewprofilepage/user-id/5546207) -- Welcome to the Atlassian Community!

If you read the other answers in this thread, you will find the solution:

* remove the JQL from the trigger
* use the JQL with the Lookup Issues action
* then use the lookup results in your message

Kind regards,  
Bill


author: Bill Sheboy
body: Hi [@Salim Bouassida](/t5/user/viewprofilepage/user-id/4246823)

As Curt noted, your rule has JQL in the scheduled trigger. And for Jira Cloud, this mean it will try to execute for each issue.

Two possible solutions are:

1. better solution: trigger your rule on "sprint started" instead of a schedule, and send the information using {{sprint.goal}} as each of the sprints start. This will create one Slack message for each sprint start.
2. brittle solution: remove the JQL from the trigger, and instead use it with a Lookup Issues action. Then grab the information for the open sprints with {{lookupIssues.sprint.distinct.goal}} which will list *all sprint goals found*.

Solution 2 is brittle because you may have carried over work from prior sprints, and when you do the wrong goals could be listed.

Kind regards,  
Bill

comments: author: Curt Holley
body: Option one is the go for sure!!! A much better solution indeed [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)   
?


author: Salim Bouassida
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) [@Curt Holley](/t5/user/viewprofilepage/user-id/3527535) ,

Thank you for your insights, it does help a lot with the reflection.

<br />

The automated slack message is a reminder a few days before the sprint review, so the option 1 does not work in my situation ?

I could remove the lookup from the trigger and have a Lookup Issues action, but that still creates a message for each issue in search.

1- Variable

{{#issue.customfield_10015}} {{#if(equals (state, "active")) }} {{goal}} {{/}} {{/}}

Gives me the right sprint goal, but 20 + times

2- Variable

{{lookupIssues.sprint.distinct.goal}}

Gives me current and past sprint goals, but 20 + times

**I wonder if I can change the variable (1) to only include the sprint goal once (not for each issue)?**

**![Capture d?e?cran 2022-10-19 a? 09.07.35.png](https://community.atlassian.com/t5/image/serverpage/image-id/221485i1AA0F47236ECC3D9/image-size/large?v=v2&px=999 "Capture d?e?cran 2022-10-19 a? 09.07.35.png")**

I saw [@Curt Holley](/t5/user/viewprofilepage/user-id/3527535) recommendation to use a label on one ticket in the sprint, and use that as a lookup, but I want to make the automation so simple, that the team doesn't need to do anything if I'm not there (ideally)


author: Bill Sheboy
body: For method 1, the work-around is to gather the goals (with repeats) using a delimiter, and then split them again to grab just the first one.

For method 2, if you believe the lookup will contain just the issues you want, you can grab just one issue using first (or last), and then access the field:

{{lookupIssues.first}}


author: Curt Holley
body: Hi [@Salim Bouassida](/t5/user/viewprofilepage/user-id/4246823)   

It is going to be to do with the fact that you have the JQL in the Scheduled trigger.   
As that means the rule will action for every issue returned from that trigger.  
So, at a high level, you need to have a JQL that will only find one issue.

<br />

Best idea I can think of (off the top of my head) is add a label to an issue in the sprint and add that into the JQL so it only finds that one issue....not ideal, but....food for thought perhaps?  

Good luck!!


Tags: jira-cloud

sprint