# Say it ain't so - Template Variables Can't Be Used With Alerts!?

**URL:** <https://community.grafana.com/t/say-it-aint-so-template-variables-cant-be-used-with-alerts/46072>\
**Category:** Time Series Panel\
**Tags:** alerting\
**Created:** [April 14, 2021, 4:30pm UTC](https://community.grafana.com/t/say-it-aint-so-template-variables-cant-be-used-with-alerts/46072 "2021-04-14T16:30:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kshull](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kshull](https://community.grafana.com/u/kshull)\
**Post date:** [April 14, 2021, 4:30pm UTC](https://community.grafana.com/t/say-it-aint-so-template-variables-cant-be-used-with-alerts/46072/1 "2021-04-14T16:30:49Z")

</div>

One of the main deciding factors for me using Grafana over Kibana was the power of templating. I’ve created dashboards that leverage variables which allow the user to easily switch between one API or another and in addition, the environments that they’d like to view.

Now I’m ready to set up alerting and to wrap all my work up in a nice, neat bow.

To my surprise, I’be been met with the “Can’t use variables in query with alerts” message.

So now what do I do? Is there a workaround for this? Does that mean I have to create distinct, non-templatized queries for my APIs?

---

<div class="post-metadata">

**Author:** ![ivanahuckova](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/ivanahuckova/32/8541_2.png) [@ivanahuckova](https://community.grafana.com/u/ivanahuckova)\
**Post date:** [April 16, 2021, 8:26am UTC](https://community.grafana.com/t/say-it-aint-so-template-variables-cant-be-used-with-alerts/46072/2 "2021-04-16T08:26:42Z")

</div>

Hello @kshull, you can follow this feature request for updates on using template variables with alerting. As you can see in the last comment, there is currently a work done on this.

> Grafana team has picked up the work on Alerting and we’re in the process of redesigning it to make the best possible alerting experience happen

> <https://github.com/grafana/grafana/issues/6557>
>
> It would be pretty useful if grafana would support alerting for queries using te…mplate variables. The way I see it work it would be as follows:
> 
> 1. Generate queries foreach template variable combination (discarding template variable for \_\_all\_\_) 
> 2. When generating queries, consider the frozen list if the template variable is set to never refresh, else update the template variable list
> 3. Allow filtering (trough regex or by providing a static value) for each template variable
> 
> The current workaround is to use an invisible wildcard metric, but the problem I see with this approach is that it loses context.

---

<div class="post-metadata">

**Author:** ![kshull](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@kshull](https://community.grafana.com/u/kshull)\
**Post date:** [April 16, 2021, 5:24pm UTC](https://community.grafana.com/t/say-it-aint-so-template-variables-cant-be-used-with-alerts/46072/3 "2021-04-16T17:24:56Z")

</div>

That’s good to know. Thank you!
