Product: PowerShell Universal
Version: 4.2.7
Greetings,
I’m working on an app to pull information from various APIs for a single workstation. I want to be able to pass the workstation name into the UD app via URL using the "?workstationname=WORKSTATIONNAME"
query. If the query was used I’d like it to populate the textbox with the machine name that was passed in and automatically execute the contents of the button’s -OnClick
scriptblock. I’d also like the page to be able to be used manually where a user would enter the workstation name, then click the button and get the same information as if there had been a device name passed in via the query.
I’m seeing some pretty strange behavior from how I’ve implemented, though, and am at a bit of a loss. I’ve tried multiple rewrites and different placements and organizations of the various pieces of logic that do what I want to no avail.
The first code block below seems to work the first time the page is deployed (when I click save in the PSU app “Code” window) but does not work subsequent times until it’s redeployed again. On subsequent runs the $workstationName variable is null and isn’t passed into the body of the code.
Also of note; this doesn’t seem to work at all if I splat the New-UDApp params (the second code block), which would be my preferred method of creating my apps for the sake of clarity and future management. The $workstationName variable is always null.
Both of these work as expected when the button is clicked, both in the stripped-down code below and my actual code.
Am I missing knowledge on something to do with the session or page variable scopes? I’m relatively new to PSU and don’t quite understand the idea of using different pages or endpoints in the scope of PSU yet.
https://FQDN/stuff?workstationname=WORKSTATIONNAME
Works when saved/redeployed the first time, then does not work subsequent times.
New-UDApp -Title "Workstation Info" -Content {
New-UDLayout -Columns 5 -Content {
New-UDPaper -Id "inputPaper" -Content {
New-UDElement -Tag "span" -Content {
New-UDStack -Direction Row -Spacing 2 -Content {
If (-not [String]::IsNullOrEmpty($Query["workstationname"])) {
New-UDTextbox -Id "workstationTextbox" -Label "Workstation" -Value $Query["workstationname"]
}
Else {
New-UDTextbox -Id "workstationTextbox" -Label "Workstation" -Placeholder "5CG123XXX" -Autofocus
}
New-UDButton -Id "buttonStart" -Style $buttonStyleStart -Text "GO" -ShowLoading -OnClick {
$workstationName = (Get-UDElement -Id "workstationTextbox").Value
Show-UDToast -Message $workstationName
# Lots of other stuff
}
}
If(-not [String]::IsNullOrEmpty($Query["workstationname"])) {
Invoke-UDEndpoint -Id "buttonStart" -Session
}
}
}
}
}
Never works:
$newUdAppParams = @{
Theme = @{
palette = @{
background = @{
default = "#ADADAD"
}
}
}
Title = "Workstation Info"
Logo = ""
HeaderContent = { New-UDButton -Icon (New-UDIcon -Icon "Home") -Text "Home" -Style @{background = "#1A3A6A" } -OnClick { Invoke-UDRedirect -Native "/home" } }
HeaderBackgroundColor = "#FFFFFF"
HeaderColor = "#000000"
DisableThemeToggle = $true
Content = {
New-UDLayout -Columns 5 -Content {
New-UDPaper -Id "inputPaper" -Content {
New-UDElement -Tag "span" -Content {
New-UDStack -Direction Row -Spacing 2 -Content {
If (-not [String]::IsNullOrEmpty($Query["workstationname"])) {
New-UDTextbox -Id "workstationTextbox" -Label "Workstation" -Value $Query["workstationname"]
}
Else {
New-UDTextbox -Id "workstationTextbox" -Label "Workstation" -Placeholder "5CG123XXX" -Autofocus
}
New-UDButton -Id "buttonStart" -Style $buttonStyleStart -Text "GO" -ShowLoading -OnClick {
$workstationName = (Get-UDElement -Id "workstationTextbox").Value
Show-UDToast -Message $workstationName
# Lots of other stuff
}
}
If(-not [String]::IsNullOrEmpty($Query["workstationname"])) {
Invoke-UDEndpoint -Id "buttonStart" -Session
}
}
}
}
}
}
New-UDApp @newUdAppParams