New-UDButton -Onclick actions


#1

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" }
            }
        }

#2

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.


#3

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 )

#4

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


#5

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