# How can I change template varibale in a react plugin in grafana 7.0?

**URL:** <https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345>\
**Category:** Grafana Plugin Development\
**Created:** [June 2, 2020, 4:17pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345 "2020-06-02T16:17:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirzaei69](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/amirzaei69/32/11186_2.png) [@amirzaei69](https://community.grafana.com/u/amirzaei69)\
**Post date:** [June 2, 2020, 4:17pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/1 "2020-06-02T16:17:10Z")

</div>

I want to change template variable from a plugin which I developed in React. I check two previous topics about updating the template variables. They say that I have to use variableSrv but how can I access this variable in grafana 7.0 and React?

---

<div class="post-metadata">

**Author:** ![marcusolsson](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/marcusolsson/32/7922_2.png) [@marcusolsson](https://community.grafana.com/u/marcusolsson)\
**Post date:** [June 2, 2020, 6:53pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/2 "2020-06-02T18:53:47Z")

</div>

`variableSrv` is going away for upcoming versions of Grafana. I’d recommend that you take a look at `LocationSrv` to update the template variable using the URL:

For example,

```auto
getLocationSrv().update({
  partial: true, 
  query: {
    'var-instance': instanceName,
  }, 
  replace: true,
});

```

For more information on the options, check out [LocationUpdate](https://github.com/grafana/grafana/blob/1e543d5ac12d7a47310e25768a88fb2ab0cf7820/packages/grafana-runtime/src/services/LocationSrv.ts#L9-L40).

---

<div class="post-metadata">

**Author:** ![amirzaei69](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/amirzaei69/32/11186_2.png) [@amirzaei69](https://community.grafana.com/u/amirzaei69)\
**Post date:** [June 2, 2020, 7:48pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/3 "2020-06-02T19:48:41Z")

</div>

Thanks for your reply. I test this method, URL get updated but the selector of variable and the dependent panels do not update. How should I force updating the panels and selector of variables?

---

<div class="post-metadata">

**Author:** ![marcusolsson](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/marcusolsson/32/7922_2.png) [@marcusolsson](https://community.grafana.com/u/marcusolsson)\
**Post date:** [June 3, 2020, 6:55am UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/4 "2020-06-03T06:55:13Z")

</div>

Just learned that updating links this way is currently broken, and that we’re working on fixing it. You can follow the progress here: [https://github.com/grafana/grafana/pull/25192](https://github.com/grafana/grafana/pull/25192)

---

<div class="post-metadata">

**Author:** ![juancarlosrubalcaba](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@juancarlosrubalcaba](https://community.grafana.com/u/juancarlosrubalcaba)\
**Post date:** [July 6, 2020, 2:09pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/5 "2020-07-06T14:09:35Z")

</div>

Hello, I follow the the code example from @marcusolsson and it works but Grafana start to make request until get an error:

`Unhandled promise rejection InternalError: "too much recursion" _invoke runtime.js:263 t runtime.js:97 Ht app.bb5d8fb9085bbb733af9.js:2 i app.bb5d8fb9085bbb733af9.js:2 Xt app.bb5d8fb9085bbb733af9.js:2 H es.promise.js:233 Xt app.bb5d8fb9085bbb733af9.js:2 t actions.ts:20 $/</</< Redux i store.ts:27 e adapter.ts:29 c runtime.js:45 host-report-errors.js:6:56`

Did you have this error also?

---

<div class="post-metadata">

**Author:** ![raulsperoni](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/raulsperoni/32/11417_2.png) [@raulsperoni](https://community.grafana.com/u/raulsperoni)\
**Post date:** [March 11, 2021, 2:08pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/6 "2021-03-11T14:08:17Z")

</div>

Hi, I’m trying to use this method to update variables. Right now I’m seeing:

new\_variable=new\_value

in the URL parameters so it works. Is this the way to add ad hoc filters for elasticsearch datasource? If so, how do I change the equals to something else?

Thank you!

This is what I’m trying to achieve: [Set ad hoc filter from Panel Plugin](https://community.grafana.com/t/set-ad-hoc-filter-from-panel-plugin/26741)

---

<div class="post-metadata">

**Author:** ![yt0](https://avatars.discourse-cdn.com/v4/letter/y/e0b2c6/32.png) [@yt0](https://community.grafana.com/u/yt0)\
**Post date:** [June 2, 2021, 4:55pm UTC](https://community.grafana.com/t/how-can-i-change-template-varibale-in-a-react-plugin-in-grafana-7-0/31345/7 "2021-06-02T16:55:28Z")

</div>

Be careful that on variable change url changes such as `var-${variableName}` ; thus the ‘var-’ in marcusolsson’s answer.
