JQL query for Send Slack message (automation in Jira)
Asked by George Davitaya:

Hi, their!

I am newbie in Automatisation Jira

I have a issue, I need to create a request for a JQL query for automation in Jira  
If there are tasks for approval, then send a message in Slack with a summary of tasks, if there are no tasks for approval, send a message "no tasks"

but when using the if function, I receive a message for each task, I think that the issue is in the request itself, how can I make the request correctly?![4.png](/t5/image/serverpage/image-id/326263iB71C59951E94DB9B/image-size/large?v=v2&px=999 "4.png")![5.png](/t5/image/serverpage/image-id/326262i1170CA556BCF2B20/image-size/large?v=v2&px=999 "5.png")


Answers:
author: Walter Buggenhout
body: Hi [@George Davitaya](/t5/user/viewprofilepage/user-id/5507173) and welcome to the Community!

{{lookupissues}} as you are using it is a smart value, it is not a JQL filter. In the use case, as you describe it, you should not add a JQL filter to your rule trigger, but instead run a **Lookup Issues** action first, with the appropriate filter to retrieve the issues you need. That may be something like this

```
status = "Waiting for Approval"
```

After that, you can use the {{lookupIssues}} smart value to refer to those issues and use it in conditions and further actions. The overall framework of your automation rule would then look like this:

![Screenshot 2024-05-28 at 12.48.21.png](https://community.atlassian.com/t5/image/serverpage/image-id/326301iF5AD57132F76E8BD/image-size/large?v=v2&px=999 "Screenshot 2024-05-28 at 12.48.21.png")

I used {{lookupIssues.size}} to count the number of issues returned by the filter. If there are 0, you can send a message that there is nothing to see here (or do nothing at all), and use the **else** part to send the desired message.

I used the *log action* because I don't have a Slack integration in my test instance, but I suppose you can see where your Slack messages should be ...

Hope this helps!

comments: author: George Davitaya
body: Hello! [@Walter Buggenhout](/t5/user/viewprofilepage/user-id/783225)

Unfortunately this still doesn't work for me(

Are you sure that status = "Waiting for Approval" is the right request? I still receive a message for every task in Slack

And if there is no task in the status "Waiting for Approval", I don't receive notifications(![10.png](https://community.atlassian.com/t5/image/serverpage/image-id/326312i47FBFDDD253B2545/image-size/large?v=v2&px=999 "10.png")![9.png](https://community.atlassian.com/t5/image/serverpage/image-id/326309i6095C6F8987F8FD3/image-size/large?v=v2&px=999 "9.png")![8.png](https://community.atlassian.com/t5/image/serverpage/image-id/326311iB05BABD8FA2F6372/image-size/large?v=v2&px=999 "8.png")![7.png](https://community.atlassian.com/t5/image/serverpage/image-id/326310i37C31BED0B852E28/image-size/large?v=v2&px=999 "7.png")


author: Walter Buggenhout
body: Hi [@George Davitaya](/t5/user/viewprofilepage/user-id/5507173),

No, of course I am not sure if that is the correct JQL ? - I am not familiar with how your Jira configuration has been set up. It should be whatever it needs to be to pull a list of issues that need approval according to how that has been set up for you.

Since I notice that you tagged JSM in your question, it is possible that the below might work:

```
approval = pending()
```

That is the way you can search for the issues marked for approval following JSM's default behaviour.

But before applying it to your rule, go to the issue navigator in Jira first (via Filters \> View all issues) and try out the provided query option first to make sure they return the right results. Then apply the correct JQL to your automation rule.

And again: **uncheck the box** *"run a JQL search ..."* from your rule trigger and replace it with the lookup issues action in my screenshot. As it literally says in the screenshot, your current setup *"executes the action for every issue in the query"*


author: George Davitaya
body: It worked Thanks for your help!


Tags: cloud

jira-service-management

jira-service-management-cloud