Grafana v11.6: how to extract variable (type = datasource) and feed it to URL?

I have a dashboard with 2 dashboard variables “$region” and “$customer”.

I created alert Notification template which populates “$customer” with a value found in data from datasource like this:

{{ $var_customer := index .Labels “kubernetes_namespace.labels.deployment-name.keyword” | urlquery }}

At the final lines of Notification template i create a URL to the dashboard with dynamic variable “$var_customer” like this:

{{ $dashboard_url := printf “%s?orgId=%d&timezone=%s&var-customer=%s” $base_url $org_id $timezone $var_region $var_customer }}

So basically “$var_customer” in URL equals “$customer” in the dashboard.

This works fine.

But i havent figured out how to dynamically populate the “$region” variable.

Contrary to “$customer”, the “$region” is a Datasource type variable, not Query type. I cannot extract the region value the same way i extract customer value because region simply does not exist in the data.

The region name is found here:

Is there anyway to extract it and use in Notification template to dynamically populate URL variable?

Datasource variables are currently supported only in dashboards. For alert rules, you must explicitly select a single datasource.

Grafana Alerting does not yet support creating one “generic” alert that swaps datasources dynamically.

However, to streamline alert rule creation, you can manage alert rules as code (Terraform, API, etc.), or duplicate an existing alert and change the DS.

Within notification templates, you can use query labels and user-defined labels.

If you cannot get the region from the query, I’d set a custom label such as region="<value>" on each alert and then reuse the same notification template across alerts.