New-UDStepper - OnFinish multiple execution

Resolved

New-UDStepper - OnFinish multiple execution

avatar
Product: PowerShell Universal
Version: 5.5.1

Hi,

does anyone has an idea or knows how to prevent steppers to execute the -OnFinish scriptblock twice or more times when clicking fast on “finish”?

Code to test:

new-udstepper -id "main_stepper" -children {
    new-udstep -label "just a step 1" -onload {
        new-udtextbox -label "jsut a empty box, for now" -id "textbox_mytextbox"
    }
    new-udstep -label "just a summary" -onload {
        $bodydata = $body | convertfrom-json
        new-udtypography -text "test my input: " -fontweight "bold"
        new-udtypography -text $bodydata.context.textbox_mytextbox
    }
} -onfinish {
    $bodydata = $body | convertfrom-json
    show-udtoast -message "$(get-date -format u) - $($bodydata.textbox_mytextbox)" -duration 5000
}

avatar

Recommended Answer

Nevermind,I found a solution using $page: variables.

If anyone runs into this problem:

$Page:OnFinishLimit = 0
new-udstepper -id "main_stepper" -children {
    new-udstep -label "just a step 1" -onload {
        new-udtextbox -label "jsut a empty box, for now" -id "textbox_mytextbox"
    }
    new-udstep -label "just a summary" -onload {
        $bodydata = $body | convertfrom-json
        new-udtypography -text "test my input: " -fontweight "bold"
        new-udtypography -text $bodydata.context.textbox_mytextbox
    } -id "step_finalStep"
} -onfinish {
    if(++$Page:OnFinishLimit -gt 1) {
        continue
    } else {
        $bodydata = $body | convertfrom-json
        1..10000 | foreach-Object { write-host "test $_" }
        show-udtoast -message "$(get-date -format u) - $($bodydata.textbox_mytextbox)" -duration 5000
    }
}

All Comments (3)

avatar
(anonymous user)

I’m not able to replicate your issue. No matter how fast I click on finish. So your issue might be with your setup.

But anyways this is some pseudo code that might help - If you use a combination of If and try-catch-finally, you can control how many times your code is executed on the onfinish part. Then you can either add null to your body and use that with an IF statement or just remove the last element from the stepper.

I’ve done both below, but I can’t test it on my setup, so you will have to play around with it.


New-UDApp -Content {

    new-udstepper -id "main_stepper" -children {
        new-udstep -label "just a step 1" -onload {
            new-udtextbox -label "jsut a empty box, for now" -id "textbox_mytextbox"
        }
        new-udstep -label "just a summary" -onload {
            $bodydata = $body | convertfrom-json
            new-udtypography -text "test my input: " -fontweight "bold"
            new-udtypography -text $bodydata.context.textbox_mytextbox
        } -Id "FinalStep"
    } -onfinish {

        If ($null -eq $body) {

            # Do nothing

        } else {


            try {

            $bodydata = $body | convertfrom-json
            show-udtoast -message "$(get-date -format u) - $($bodydata.textbox_mytextbox)" -duration 5000
           
            
            }
            catch {
                <#Do this if a terminating exception happens#>
            }
            finally {
                Remove-UDElement -Id "FinalStep"
                $body = $null
            }

            

        }
    }
}