# Global Variables in Canvas

**URL:** <https://discuss.elastic.co/t/global-variables-in-canvas/169871>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [February 25, 2019, 4:08pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871 "2019-02-25T16:08:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesNotJamez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesnotjamez/32/45736_2.png) [@JamesNotJamez](https://discuss.elastic.co/u/JamesNotJamez)\
**Post date:** [February 25, 2019, 4:08pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/1 "2019-02-25T16:08:19Z")

</div>

Is it possible to define a global variable in Canvas. At the moment I am defining a target, but when I update this target I have to change queries of each individually. Thanks  
e.g.  
 ![canvas](https://us1.discourse-cdn.com/elastic/original/3X/5/f/5fb583ced6a63c5b0bcdcc034c65ae7183538cd9.png)

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [February 27, 2019, 6:58pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/2 "2019-02-27T18:58:30Z")

</div>

@JamesNotJamez I don't think this is possible.

But perhaps @Joe_Fleming or @Catherine_Liu know more?

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [March 11, 2019, 8:14pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/3 "2019-03-11T20:14:28Z")

</div>

@JamesNotJamez There's not a way to create a "global" value directly, but you could perhaps use the `urlparam` function as a substitute here. That function allows you to read a value from query params in the URL.

When you have a workpad open, the URL in your browser should look something like this: `http://localhost:5601/app/canvas#/workpad/...`

You can add query params before the `#` in there, like so: `http://localhost:5601/app/canvas?target=5000#/workpad/`

So now you have a query param named `target`, which you can use with the following expression:

```auto
urlparam param=target default=1000

```

This will read the value of `target` in the url, and if it's not set, default the value to 1000. In the URL I used above there, the value would be 5000. You can use it as a subexpression to get the value of the upper bound. As a simple and somewhat contrived example:

```auto
escount index="your-index-or-index-pattern"
| math {string "value / " {urlparam param=target default=1000}}

```

Now when you want to adjust the goal value, you can just set a new value in the URL, and it will simply use 1000 by default.

The downside is that the value in the URL isn't preserved, if you just open the workpad like normal, the value won't be there, and it'll fall back to 1000. This really only works for situations where you are linking to a workpad directly somewhere.

You gave me an interesting idea for the application though; the ability to define arbitrary metadata on a workpad, which _would_ persist, and would be easy enough to modify to update all elements. I've opened an enhancement issue to track that idea here, feel free to follow or comment: [https://github.com/elastic/kibana/issues/32928](https://github.com/elastic/kibana/issues/32928)

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [March 11, 2019, 8:15pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/4 "2019-03-11T20:15:18Z")

</div>

Oh, alternatively, you could read that goal value from some external source as well. It would be more work though, requiring you put that value somewhere you can modify it, and then write a function to go fetch it.

---

<div class="post-metadata">

**Author:** ![JamesNotJamez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesnotjamez/32/45736_2.png) [@JamesNotJamez](https://discuss.elastic.co/u/JamesNotJamez)\
**Post date:** [March 12, 2019, 8:59pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/5 "2019-03-12T20:59:14Z")

</div>

Amazing, thanks! I'll have a look into those suggestions. The URL params definitely seems like the best solution for now, but I'll follow the issue with interest to see if it leads to any new features.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 9, 2019, 8:59pm UTC](https://discuss.elastic.co/t/global-variables-in-canvas/169871/6 "2019-04-09T20:59:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
