Passing a variable from a button inside a grid to modal-based input form

I have a grid display with a Status button. I want to pass a CertificateID ($_.CertificateID in the code below) to a form that pops up in a modal window. I have a $CertificateID parameter defined in the New-UDInput endpoint to receive the variable. Haven’t been able to figure out how pass it from the grid to the modal form.

New-UDPage -Name "Certificate List" -Icon list -Content {

    $CertificateListColumns = @('CertificateID', 'Subject', 'Thumbprint', 'NotBefore', 'NotAfter')
    $CertificateListHeaders = @('CertificateID', 'Subject', 'Thumbprint', 'Start Date', 'Expire Date')

    New-UDColumn -Size 12 {
        $newUDGridSplat = @{
            FontColor       = 'White'
            Title           = "Certificate List"
            Headers         = $CertificateListHeaders
            PageSize        = 20
            Properties      = $CertificateListColumns
            BackgroundColor = 'Black'
            Endpoint        = {

                $Data | ForEach-Object {
                    [PSCustomObject]@{
                        CertificateID     = $_.CertificateID
                        Subject           = $_.Subject
                        Thumbprint        = $_.Thumbprint
                        NotBefore         = New-UDElement -Tag 'div' -Content { Get-Date($_.NotBefore) -f 'yyyy/MM/dd HH:mm' }
                        NotAfter          = New-UDElement -Tag 'div' -Content { Get-Date($_.NotAfter) -f 'yyyy/MM/dd HH:mm' }
                        Status            = New-UDButton -Text "+" -OnClick {
                            Show-UDModal -Content {
                                New-UDRow {
                                    New-UDColumn -Size 6 {
                                        New-UDInput -Title "Certificate - Status Update" -BackgroundColor black -FontColor cyan  -Id "CertFileEntryForm" -Content {
                                            New-UDInputField -Type 'select' -Name 'Status' -Placeholder 'Status'  -Values @("--Select One--", "Requires Review", "Renewed")
                                            New-UDInputField -Type 'textarea' -Name 'Notes' -Placeholder 'Notes'
                                        } -Endpoint {
                                            param(
                                                $CertificateID,
                                                $Status,
                                                $Notes
                                            )

                                            New-UDInputAction -Content (

                                                New-UDCard -Id 'CertStatusFormResults' -Content {
                                                    New-UDParagraph -Text "CertificateID = $CertificateID"
                                                    New-UDParagraph -Text "Status = $Status"
                                                    New-UDParagraph -Text "Notes = $Notes"
                                                }
                                            )
                                        }
                                    }
                                }
                            }
                        }
                    }
                }  | Out-UDGridData
            }
        }
        New-UDGrid @newUDGridSplat
    }
}
New-UDButton -Text "+" -Onclick {
   New-UDEndpoint -Endpoint {
        $id = $($ArgumentList[0])
        [Insert rest of code here]
    } -ArguementList $($_.CertificateID)
}

That should help you get that into the code so you can manipulate it.

Hope it helps!

I do something similar with AD ObjectGUIDs and that works for me.

1 Like

Thanks for that snippet. I was just coming back here to share what I got working. I got it working my simply referencing $_.CertificateID in the New-UDInput endpoint without using a parameter for it.

New-UDInput -Title "Certificate - Status Update" -BackgroundColor black -FontColor cyan  -Id "CertFileEntryForm" -Content {
	New-UDInputField -Type 'select' -Name 'Status' -Placeholder 'Status'  -Values @("--Select One--", "Requires Review", "Renewed")
	New-UDInputField -Type 'textarea' -Name 'Notes' -Placeholder 'Notes'
} -Endpoint {
	param(
		$Status,
		$Notes
	)

	New-UDInputAction -Content (

		New-UDCard -Id 'CertStatusFormResults' -Content {
			New-UDParagraph -Text "CertificateID = $_.CertificateID"
			New-UDParagraph -Text "Status = $Status"
			New-UDParagraph -Text "Notes = $Notes"
		}
	)
}
1 Like

Well, this will reduce a few lines from my code… Thanks for sharing!

is this still working ?
i actually tested the code and it doesn’t. i Think an update make it not working.