# \[Canvas\] How to pass variable as timerange to savedVisualization

**URL:** <https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [July 26, 2021, 7:55am UTC](https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602 "2021-07-26T07:55:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salman\_Ahmed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salman_ahmed/32/92121_2.png) [@Salman\_Ahmed](https://discuss.elastic.co/u/Salman_Ahmed)\
**Post date:** [July 26, 2021, 7:55am UTC](https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602/1 "2021-07-26T07:55:56Z")

</div>

I have created a canvas with multiple Kibana visualization and need to dynamically (from url parameter" pass the "from" argument of the visualization. It works until I save/run the expression at which point it changes the value to hard coded,

My url is :  
[https://test.com/app/canvas?target=60#/workpad/workpad-id/page/1](https://test.com/app/canvas?target=60#/workpad/workpad-id/page/1)

with expression

```auto
savedVisualization id="<visualization-id>" timerange={timerange from={string "now-" {urlparam param="target" default=30} "d/d"} to="now"}
| render

```

However, when I save/refresh the page the expression automatically changes to

```auto
savedVisualization id="<visualization-id>" timerange={timerange from="now-60d/d" to="now"}
| render

```

and the value now-60d/d becomes hardcoded instead of being picked up from the query string parameter ( funnily enough the first time it does pick it from the query string parameter as 60)

Also, the same issue does not occur in markdown element.

Is there are another way to pass dynamic time range values to visualizations in a canvas ? [We have mutltiple visualizations on a canvas and don't want to duplicate them just for the sake of different time ranges - also a single time filter at the top of canvas does not work because it works using default timefield which is different to visualizations and there is a custom date format]

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [August 3, 2021, 6:39pm UTC](https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602/2 "2021-08-03T18:39:32Z")

</div>

I don't see that as doable right now. But as a workaround for your timefield that is different between visualizations a solution would be field aliases added to make all timefields the same.

---

<div class="post-metadata">

**Author:** ![Salman\_Ahmed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/salman_ahmed/32/92121_2.png) [@Salman\_Ahmed](https://discuss.elastic.co/u/Salman_Ahmed)\
**Post date:** [August 12, 2021, 1:52am UTC](https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602/3 "2021-08-12T01:52:42Z")

</div>

Hi Marius,

Thank you for replying and field aliases is a good idea, however it does not solve our particular use case since the timefield is same across all visualisations its just that we need to set it once and use across all visualisations.  
We resolved it for now by adding a single timefilter element to the top of canvas but we had to create a new timestamp field with format strict\_date\_optional\_time ( the query for time filter in Canvas does not seem to pass the "format: 'strict\_date\_optional\_time'" property when it constructs the queries for Elastic hence it was failing previously and therefore we had to switch to using a new field that has strict\_date\_... in its mapping).

Thanks,

Salman

---

<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:** [September 9, 2021, 1:53am UTC](https://discuss.elastic.co/t/canvas-how-to-pass-variable-as-timerange-to-savedvisualization/279602/4 "2021-09-09T01:53:18Z")

</div>

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