Session vs Cached variables

I’m trying to develop dashboard that will be used in multiple places, with different dataset.
$Team variable is selected from dropdown list and used to get proper dataset values.
If using $Cache:Teams scope - everything is working (but dataset will be the same for all instances of dashboard), but when I switch to $Session:Team scope, Sync-UDElement from dropdown OnChange doesn’t update content of dashboard.
Is there any specifics with Session variables in compare to Cache in regards to Sync-UDElement functionality?

The session variable takes advantage of the Session ID being available in the runspace when executing commands. This seems buggy. It should “just work” in this scenario. Can you try to enable logging when setting the session variable to see if there is anything interesting in there?

You can do that with Enable-UDLogging

Enabled debugging. Got a lot of data =)
The only difference that I’ve found, was additional line in Session variable:
[Debug] SessionDriveVariableProvider GetContentWriter - Team <— This is my variable
Everything else is more or less identical, as I can see.

What’s interesting, is that I’m doing:
New-UDSelect {
##Generating content here ####
} -OnChange {
$Session:Team = $EventData
Sync-UDElement -Id XXX
##More Sync-UDElement here #####
Show-UDToast -Message “$EventData selected” -Duration 5000

I receive correct Toast message, but Sync doesn’t work for any of items.

@muravsky did you get this working?

Can you provide an example of one of the elements you are trying to sync?


No, sadly, I wasn’t able to fix it so far and this is a serious blocker for me.
Both Cookies (topic raised in separate thread) and Sessions are no working for me.

To make code more manageable, I’m using variables to create each object and then use those variables in page layout. Here are example of variable that defines drop-down list and one of objects that it update (Chart):

    $dashboard_team_select = New-UDSelect -Label "Select team" -Option {
	foreach ($hdteam in $Cache:sn_id.GetEnumerator())
		if ($($Cache:Team) -eq $($hdteam.Name))
			New-UDSelectOption -Selected -Name $($hdteam.Name) -value $($hdteam.Name)
			New-UDSelectOption -Name $($hdteam.Name) -value $($hdteam.Name)
} -OnChange {
	Show-UDToast -Message "$EventData selected" -Duration 5000
	$Cache:Team = $EventData
	Sync-UDElement -Id "Incidents"
	Sync-UDElement -Id "AMS"
	Sync-UDElement -id "Incidents_counter"
	Sync-UDElement -id "Incidents_counter_2"
	Sync-UDElement -id "AMS_counter_1"
	Sync-UDElement -Id "New_Incidents"
	Sync-UDElement -Id "New_Incidents_counter"
	Sync-UDElement -Id "Awaiting_Incidents"
	Sync-UDElement -Id "tiketspersupporter"
	Sync-UDElement -Id "tiketsperstatus"

$chart_tickets_per_status = New-UDChart -Id "tiketsperstatus" -Title "Per state" -AutoRefresh -Type Doughnut -Endpoint {
	if ($Cache:sn_id[$Cache:Team][1])
		$perstatus = @{ }
		$Cache:sn_id[$Cache:Team][1] | Foreach-Object {
			if ($perstatus[$($_.state)])
				$perstatus[$($_.state)] = $perstatus[$($_.state)] + 1
				$perstatus[$($_.state)] = 1
		$perstatus.GetEnumerator() | ForEach-Object {
			[PSCustomObject]@{ Name = $_.Key; "Ticket count" = $_.Value }
		} | Out-UDChartData -DataProperty "Ticket count" -LabelProperty "Name" -BackgroundColor $Cache:chartColors
	else { return }
} -Options @{
	responsive = $True
	legend = @{
		display   = $True
		fullWidth = $true
		position  = "bottom"
		labels    = @{
			fontColor = 'white'

When I use this code with $Cache:Team, it’s working. If it’s used with $Session:Team - it doesn’t work. Specifically, change in dropdown list doesn’t refresh Elements nor save variable.

With current limitations - I can’t make multi-user web application.

BTW, maybe somebody can advice if one of authentication methods in this framework will allow me to overcome this problem or implement this functionality on some other, more correct way?

Try wrapping the New-UDChart inside a New-UDElement e.g.:
New-UDElement -Tag “div” -Endpoint {
$chart_tickets_per_status = New-UDChart …

I’ve done that with some controls where the control with the Endpoint didn’t want to sync, but within another Endpoint it did.

1 Like

I’ve tried one more time with newest version of UDDashboard. Situation didn’t change.
Session variables just didn’t work. I can’t assign it. Wile in absolutely the same situation, but with Cached variables - everything is working fine. But this doesn’t allow me to create multi-user application.
I see a lot of examples on forum where it Session variables are used. I’ve tried those examples as it and failed, the same was as with my own code.
Is there any pre-requirements for Session level variables? Debug doesn’t give any errors or even hint toward solution.

Please assist.