UDButton Problem

I am having an issue with getting the button, within my UDGrid, to function the way I want it to.

My grid, look like this:

I want the ‘Latest Report’ button, to redirect to a dynamic page and send the Instance Name to the page.

Here is the code for my UDGrid:

New-UDGrid -Id 'sqlServerInfoGrid' -Headers @('Instance Name', 'Function', 'Site', 'Report', 'Edit') -Properties @('ServerName', 'ServerFunction', 'Site', 'Report', 'Edit') -Endpoint {
	$dashboardSettings.SQLServers | ForEach-Object {
		[PSCustomObject]@{
			ServerName = $_.ServerName
			ServerFunction = $_.ServerFunction
			Site = $_.Site

			#ToDo: Add SQL Version 
			<# SQLVersion = {
				$SQLverQuery = "SELECT SERVERPROPERTY('productversion') AS version"
				$sqlVer = Send-SQLReadQuery -sqlserver $_.ServerName -sqlcreds $Cache:userCreds -sqlquery $SQLverQuery

				$sqlVer.version
			} #> 

			# Add View Latest Report Button
			Report = New-UDButton -Text 'Latest Report' -OnClick {New-UDInputAction -RedirectUrl "/sqlreport/${$_.ServerName}"}

			# Add Edit Button
			Edit = New-UDButton -Flat -Icon edit #ToDo: Add Additional Functionality Later...
		}
	} | Out-UDGridData 
} -NoFilter -DefaultSortColumn '1' -DefaultSortDescending -NoPaging -NoExport

Right now, I’m Not getting an error, but the button doesnt appear to do anything…

Any thoughts on what I’m doing wrong?

Hi @darkgarage!

Try “invoke-udredirect” in the onclick endpoint, should work :slight_smile:

OK, I’ll give that a shot.

Thanks

@BoSen29

Thanks!

That worked.

Now onto the next ‘hurdle’. :smiley:

1 Like

@BoSen29

Now, the question is what do I need to do to not get a ‘Page Not Found’ error when trying to visit the Dynamic Page?

Right now, it’s pretty simple…Here’s the Code, for the Dynamic Page:

New-UDPage -Url "/sqlreport/:sqlInstance" -Endpoint {
    param($sqlInstance)
    New-UDHeading -Id 'sqlReportHead' -Text 'SQL Server Health Report'
    foreach ($svr in $sqlInstance) {
        New-UDCollapsible -Items {
            New-UDCollapsibleItem -Title $sqlInstance -Content { 'This is placeholder text'}
        }
    }
}

I’ve added the page to my Dashboard Script:

$Pages = @()
$Pages += . (Join-Path $PSScriptRoot "pages\home.ps1")
$Pages += . (Join-Path $PSScriptRoot "pages\sql.ps1")
$Pages += . (Join-Path $PSScriptRoot "pages\sqlreport.ps1" )

Not sure where the ‘error’ is…

Any more miraculous thoughts? :smiley:

@darkgarage
Hmm,
do you have any other pages with the url “/sqlreport”

If not, i can compare it to my dynamic pages in the morning!

@BoSen29
No, there is only the single ‘page’ with that URL.

Hi again @darkgarage

Looks good compared to my working dyn pages, could you do
enable-udlogging -level debug -filepath %filepathtologfile%

and see if anything relevant shows up there?

1 Like

Where should I place that command? in the page file, or just at the Powershell console?

Nevermind, figured it out.

1 Like

Top of your dashboard.ps1 file,

It enables logging globally on the dashboard.

@BoSen29
Not really sure what I should be looking for, in the debug log file…

I found this entry, in Log:

16:09:25 [Info] Microsoft.AspNetCore.Hosting.Internal.WebHost Request starting HTTP/1.1 GET http://localhost:10001/sqlreport/

But I’m not seeing any ‘errors’…

@darkgarage
Try manually navigating to http://localhost:10001/sqlreport/somerandomvalue

@BoSen29
OK, that works.

So, looks like my issue is how I am passing the ‘ServerName’ to the -OnClick action…

I think there is a problem with this line:

Report = New-UDButton -Text 'Latest Report' -OnClick {Invoke-UDRedirect -Url "/sqlreport/${$_.ServerName}"}

Try using your ServerName variable instead. It's probably a problem with the _ variable being wiped within your OnClick handler. it’s a PS scoping problem and nothing you’re doing wrong.

Report = New-UDButton -Text 'Latest Report' -OnClick {Invoke-UDRedirect -Url "/sqlreport/$ServerName"}
2 Likes

Ok, that worked, but I needed to add a ‘variable declaration’ for that variable into the script block.

Thanks.