New-UDCodeEditor Flashing then goes blank

I have a dashboard that technicians can access to kick off an script in PSU.
This launches a PowerShell script that calls an external .BAT file using Invoke-Command.
It has worked wonders, until 2.4.0. Holding off on 2.5.X, because I was not sure if the method I am doing would break further.

What happens is the techs hit ‘Run’, the button changes to ‘Running’ and the output CodeEditor flashes and I can briefly see it populating the output of the script, then when it is done; the Window is empty.

                New-UDButton -Text 'Run' -OnClick {
                Set-UDElement -Id 'button' -Properties @{
                    disabled = $true 
                    text = "Running"
                }
                Connect-PSUServer -ComputerName http://localhost:5000 -AppToken $AppToken
                $Job = Invoke-UAScript -Script 'Redefine.ps1' -OS $os -storeNum $storeNum
                while($Job.Status -ne 'Completed')
                {
                    Start-Sleep 1
                    $Output = (Get-UAJobOutput -Job $Job).Data -join ([Environment]::NewLine)
                    Set-UDElement -Id 'codeEditor' -Properties @{
                        code = $Output 
                    }
                    $Job = Get-UAJob -Id $Job.Id
                }

                Show-UDToast -Message "Job ran successful! Check output for status." -Duration 10000
                Set-UDElement -Id 'button' -Properties @{
                    #disabled = $false 
                    text = "Finished"
                }
            } -Id 'button'
Product: PowerShell Universal
Version: 2.4.0

I just tried this on 2.5.4 and this is what I’m seeing. I don’t have any issue with it going blank but it does seem to not print the last output. I added one more call to Get-UAJobOutput outside of the loop to get the job output after it’s completed.


New-UDDashboard -Title 'Test' -Content {
             New-UDButton -Text 'Run' -OnClick {
                Set-UDElement -Id 'button' -Properties @{
                    disabled = $true 
                    text = "Running"
                }
                $Job = Invoke-UAScript -Script 'Redefine.ps1'
                while($Job.Status -ne 'Completed')
                {
                    Start-Sleep 1
                    $Output = (Get-UAJobOutput -Job $Job).Data -join ([Environment]::NewLine)
                    Set-UDElement -Id 'codeEditor' -Properties @{
                        code = $Output 
                    }
                    $Job = Get-UAJob -Id $Job.Id
                }

                $Output = (Get-UAJobOutput -Job $Job).Data -join ([Environment]::NewLine)
                Set-UDElement -Id 'codeEditor' -Properties @{
                        code = $Output 
                    }

                Show-UDToast -Message "Job ran successful! Check output for status." -Duration 10000
                Set-UDElement -Id 'button' -Properties @{
                    #disabled = $false 
                    text = "Finished"
                }
            } -Id 'button'

            New-UDCodeEditor -id 'codeEditor' -Height 1000
}

This resolved the issue for me. I don’t know what would have changed in 2.4 to prevent it from working properly.

1 Like

@adam Thank you! I will try that after updating to 2.5.4.