Variables / State

Product: PowerShell Universal 3.4.4 (3323417812)

I have a question about variables and state:

On a page, I have an UDSelect with a few options. That value is used to query a database and populate a variable that a UDTransferList uses to create it’s options. When the selection changes on the Select, I want to use that value to query the database and get a new list and update the UDTransferList options.

So far I have that working using onchange for the UDSelect , getting the value, retrieving the list and setting a Session Variable, then the UDTransferList is wrapped in a New-UDElement and I call the Sync on the Wrapper UDElement.

The catch is, I would like to be able to open multiple tabs in the same browser and have them independent. But, using a session variable, it is no longer isolated to the page, and as expected it is instead messing with the other tab.

Is there an easier way to do this? I have tried it without the session specifier, but the wrapper udelement and the transferlist only see the old values. I have tried with “global:” specifier on the variable and also doesn’t get updated values.

Thank You. Dave

There currently isn’t a way to do this. We have an open issue for $Page: scoped variables that would behave as expected.

A work around would be to use the $ConnectionID variable because it would be independent of session but tied to the current page.

You’d have to do something like:

New-UDSelect -Option {
    New-UDSelectOption -Name 'Test' -Value 'Test'
} -OnChange {
    Set-Item -Path "Session:$($ConnectionID)_MySelect" -Value $EventData
}

New-UDButton -OnClick {
    $Value = Get-Item "Session:$($ConnectionID)_MySelect" 
     Show-UDToast $Value
}

Great, thank you! I’ll use that option for now. Any idea when the $Page scope will be implemented?

It’s currently not slated for 3.6 so likely 3.7, which will be a January 2023 release.

1 Like

Great to hear this Adam :slight_smile:

Workarounds are easy enough (once you know what to do), but having $Page will be a nice QoL and ease of use feature. Thanks for all your work!

I need this really bad.

As Adam stated above, it’s he’s aiming for 3.7 which would be in January. Do the workarounds in this thread not work for you?

we are rewriting our dashboards now :frowning: