Dashboard - Get output of invoke-PSUscript

Product: PowerShell Universal
Version: 4.3.2

Hello,

We are trying to retrieve the output of script dynamically in a dashboard.
Here is the code :

New-UDButton -Text 'Run Job' -OnClick {
        Set-UDElement -Id 'button' -Properties @{
            disabled = $true 
            text     = "Running"
        }
        
        $Job = Invoke-PSUScript -Script 'Build-Package.ps1' -package '7zip'

        while ($Job.Status -ne 'Completed') {
            Start-Sleep 1
            $Output = (Get-PSUJobOutput -Job $Job).Data -join ([Environment]::NewLine)
            Set-UDElement -Id 'codeEditor' -Properties @{
                code = $Output 
            }

            $Job = Get-PSUJob -Id $Job.Id
        }

        Set-UDElement -Id 'button' -Properties @{
            disabled = $false 
            text     = "Run Job"
        }
    } -Id 'button'

    New-UDCodeEditor -Id 'codeEditor' -ReadOnly -Height 500

The UDCodeEditor remain empty and can’t find why.

During my testing, I ran into some issues with getting the job output, but settled on this in one of my apps. I don’t remember if the issue was with trying to get the output with the -Job parameter, but I know that it works with the -JobId parameter:
Get-PSUJobOutput -Integrated -JobId $EventData.Id

Also, if you haven’t done so, I would also recommend that you verify that the your job produced output by sticking it in a toast or modal first.

hi
here is my code im using it successfully for a long time and its best that i was able to develop
it displays code output in Modal so i dont know if it suit your needs, but this way its fast and clean
if you want to display it in static element in dashboard , probelamy you have to make it dynamic and sync it using sync-udelement

$disabled_textbox_style = ' .Mui-disabled { -webkit-text-fill-color: #000000;}'


New-UDButton -Text "Process" -Icon (New-UDIcon -Icon 'CaretSquareRight' -Solid -Size 2x) -OnClick {
	Show-UDModal -FullWidth -MaxWidth md -Persistent -Dividers -Content {
		New-UDStyle -Style $disabled_textbox_style -Content {
            New-UDTextbox -Id 'codeEditor' -Multiline -Disabled -FullWidth  -Value "" 
        }
    } -Header {New-UDTypography -Text "Script results:"
	} -Footer {
        New-UDButton -Text "Close" -OnClick {Hide-UDModal}
        New-UDButton -Text "Send me report" -id send_mail -Disabled  -OnClick {}
	}
	$job_name = "Create_account.ps1"
    $Job = (Invoke-PSUScript -Script $job_name -input_data $page:input_array_new -Integrated )

    while($Job.Status -ne 'Completed')
    {
        Start-Sleep 1
        $Output_line = (Get-PSUJobOutput -Job $Job -Integrated).Data -join ([Environment]::NewLine)
        Set-UDElement -Id 'codeEditor' -Properties @{
            value = $Output_line
        }
        $Job = Get-PSUJob -Id $Job.Id -Integrated
    }
	Set-UDElement -id send_mail -Attributes @{Disabled = $false}
}
``