Global Variables in Canvas

@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:

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:

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

1 Like