New-UDButton -Onclick actions

I am using the following code to send an email as the Onclick action. I can see the Set-UDElement works, as I get the pop-up “order submitted” , but the Send-MailMessage never appears to work. Any gotchas I’m missing?

New-UDColumn -Size 2 { 
            New-UDHeading -Size 5 -Id "Submit" -Text ""
            New-UDButton -Text "Place Order" -OnClick {
                Send-MailMessage -to $recipient -subject $subject  -SmtpServer $SMTPServer -from $Sender #-BodyAsHtml $HTML
                Set-UDElement -Id "Submit" -Content { "Order Submitted" }
            }
        }

Try using manually scoping for your endpoint: https://docs.universaldashboard.io/endpoints/event-handler-endpoints#manual-variable-scoping

Pass in your Send-MailMessage variables through the -ArgumentList. UD might be having a hard time passing them into the endpoint for wahtever reason.

so like this?

New-UDButton "VM Order" -OnClick (New-UDEndpoint -Endpoint{
                              Send-MailMessage -to $ArgumentList[0] -subject $ArgumentList[1]  -SmtpServer $ArgumentList[2] -from $ArgumentList[3]
                        } -ArgumentList $Recipient $subject $SMTPServer $Sender )

think it might be combining the params and New-Input and the New-UDButton. If I strip out and use just the New-UDButton , and put specific values rather than using variables i can get it work. …more investigation

worked around it by having 2 submit buttons …1 to confirm the choices and another to email

1 Like