How to use dashboard context in experience view?


#1

Hi,

My dashboard context works perfectly as a Losant dashboard. However, when used as an experience view page, it does not seem to work. the URL is updated correctly in the browser bar when I click on my list of devices but the gauges always show attribute values for the default device.

In my device list on the dashboard I have the URL as: https://app.losant.com/dashboards/5aa5ecbcf45edf00075f9488?ctx[deviceId-0]={{deviceId}} which works correctly. But when the URL is:
https://pmyexperience.onlosant.com/testdashboard?ctx[deviceId-0]={{deviceId}}
it does not seem to work.

Ideas?


#2

Hi,
The context variable for experience views do not work the same as in dashboards, you’re going to have to pass path parameters down to the context variables.

Let’s start from the beginning. I’ll assume you have made a route called /testdashboard. You’ll need to add a path parameter like /testdashboard/{deviceId} or if you want it to be optional /testdashboard/{?deviceId} to your endpoint. Then in your workflow, for this page, you will need to pass that parameter through to your view on the Endpont Reply Node. For this example, if you to make a custom json object to return as the page data then your json template would look like { "deviceId": {{ data.params.deviceId }} }. Then in your views dashboard, you will want to set your context variable of deviceId-0 to {{ pageData.deviceId }}.

Hope this helps,
Erin


#3

Thanks Erin,

Understood… Just one more question, That would suggest that in my dashboard where I have my device list control that I click on a device to customise the dashboard, the device list URL would be …/testdashboard/?ctx[deviceId-0]={{deviceId}}&ctx[string-0]={{ valueByKey deviceTags ‘Site’ ‘key’ ‘value’ }}.

That would mean that my dashboard context would no longer work outside the user experience page? Ie just as a normal losant dashboard?


#4

That is a great point, one that I have actually never thought of before but you will have to choose which URL to use on the dashboard. My suggestion would be if you want to display the dashboard on the experience page, or if you want people to view the dashboard on Losant. If you want it on the experience page then use the experience pages URL otherwise use the one we discussed earlier.

We will try to figure out an easy way to allow you to switch back in forth between URLs like this, but currently, we do not have a helper that does what you are asking.

Thanks,
Erin