Job output on page load

What up everyone?!

Hopefully one of you can guide me to the right path.

I’ve been trying all day today to have the following accomplish. I have a page when it checks if a job is running, if so then display Code Editor box with job live output. However, when this code is hit, it does the while loop but nothing is displayed on the page other than the loading bars. Then when the while loop completes, page gets refreshed and show the completed job. Below is a snippet of what I’m using.

If more info is needed, I’ll provide as much as possible.

$Job = Get-UAJob -Id $reqstat[0].PSUJobId
            if ($Job.Status -eq 'Running') {
                New-UDRow -Columns {
                    New-UDGrid -Spacing 0 -Container -Content {
                        New-UDGrid -Item -LargeSize 10 -Content {
                            New-UDStyle -Id 'codestyle' -Style '.MuiGrid-grid-lg-10 { margin: 20px 5px; }' -Content {
                                New-UDCodeEditor -Id 'codeEditorReqProcess' -ReadOnly -Height 600

                $AppToken = 'TOKEN_HERE'
                Connect-PSUServer -ComputerName http://localhost:5000 -AppToken $AppToken

                while($Job.Status -ne 'Completed')
                    Start-Sleep 1
                    $Output2 = (Get-UAJobOutput -JobId $Job.ID).Data -join ([Environment]::NewLine)
                    Set-UDElement -Id 'codeEditorReqProcess' -Properties @{
                        code = $Output2

                    $Job = Get-UAJob -Id $Job.ID

                Invoke-UDRedirect -Url "http://localhost:5000/noc/deployer/request/view/$Id"
  other stuff here

Product: PowerShell Universal
Version: 2.2.0

Try putting your Get-UAJob call etc in a New-UDDynamic. It’s trying to load the page but is stuck in the while loop.

If you move the job into a dynamic, it will load the page and then start to load the dynamic which will check the job and allow the progress bar to show.

Kool beans!! I’ll give it a try in a few. Funny part is I thought about it using UDDynamic but quickly assumed it was not possible.


Wow!! It worked!

Thanks again for your help and advise

1 Like