New-UDButton - create new page?

Product: PowerShell Universal
Version: 3.7.10

Hola,

I got a table with all my SQL Instances, which is working just fine.

$Columns = @(
    New-UDTableColumn -Property SQLInstanceName -Title "SQL Instance Name" -ShowFilter -ShowSort
    New-UDTableColumn -Property Active -Title "Active" -ShowSort
    New-UDTableColumn -Property DateAdded -Title "Date Added" -ShowFilter -ShowSort -SortType datetime
    New-UDTableColumn -Property SQLInstanceNameButton -Title "View" -Render { 
        New-UDButton -Text "View" -OnClick { 
            New-UDPage -Title "$($EventData.SQLInstanceName)" -Url "/instances/all/$($EventData.SQLInstanceName)" -Content {
                #Query data here based on the #EventData.SQLInstanceName
            }
            Invoke-UDRedirect "/instances/all/$($EventData.SQLInstanceName)" -OpenInNewWindow
        } 
    }
)

New-UDGrid -Container -Content {
    New-UDGrid -item -SmallSize 12 -Content {
        New-UDCard -Title 'Select object type' -Content {
            New-UDStack -Direction 'column' -Content {
                $TableData = Invoke-DbaQuery -SqlInstance "dk1sqlclu01ag02" -Database "Atria" -Query "select SQLInstanceName,Active,DateAdded from SQLInstances"  
                New-UDTable -Id 'NameSelection' -Data $TableData -Columns $Columns -ShowPagination -PageSize 10 -ShowExport -ShowSort -Title "SQL Instances" -DefaultSortDirection ascending -DisableMultiSelect -HideToggleAllRowsSelected
            }
        }
    }
}

What i basically want is, when a user clicks on the “View” button, they should be redirect to a new page, and that $EventData.SQLInstanceName must be forwarded to that page, so that i can query the other tables based on the SQL Instance Name.

The new pages will be the same layout, but with different data based on the SQL Instance Name.

How do i achieve this? And where will i provide the code (New-UDGrid, etc) for that page?

Just create a new page in your dashboard like normal, but define a variable in the URL.

Here is an example from my own dashboard…

$Pages += New-UDPage -Name 'Computer Management' -URL '/computermanagement/:snid' -Content {
    . "$UDScriptRoot\ComputerManagement.ps1"
} -NavigationLayout permanent -LoadNavigation $Navigation

Then to use it and feed it data, I have this as one of the columns.

New-UDTableColumn -Property "deviceName" -Title "Device Name" -IncludeInSearch -ShowFilter -Render {
		New-UDGrid -Container -Children {
			switch -wildcard ($Eventdata.Model) {
				'Latitude*' { New-UDIcon -Icon Laptop -Size lg }
				'OptiPlex*' { New-UDIcon -Icon Desktop -Size lg }
				'Precision*' { New-UDIcon -Icon Desktop -Size lg }
				'Virtual Machine' { New-UDIcon -Icon Cloud -Size lg }
				Default {}
			}
			New-UDLink -Text $EventData.'deviceName' -url "ComputerManagement/$($EventData.SerialNumber)" -OpenInNewWindow
		}
	}

At this point, I have a variable available in that page called $snid. In this case, it’s the serial number of a computer which I then use to perform various queries to pull device information.

Hi,

Thanks for the examples - it somewhat makes sense, but im stuck with a brainfart… i believe its due to the missing $sqlid variable, but i cant figure out, where to insert it. Can you help?

This is the dashboard:

$Navigation = @(
    New-UDListItem -Label "Home" -OnClick {
        Invoke-UDRedirect -Url '/home'
    }
    New-UDListItem -Label "Instances" -Children {
        New-UDListItem -Label 'All Instances' -Icon (New-UDIcon -Icon Microsoft) -OnClick {
            Invoke-UDRedirect -Url '/instances/all'
        }
    }
)

$Pages = @()
$Pages += Get-UDPage -Name 'Instances'
$Pages += New-UDPage -Name 'Home' -Content {
    New-UDGrid -Container -Content {
    }
}
$Pages += New-UDPage -Name 'Instance' -URL '/instance/:sqlid' -Content {

}

  
New-UDDashboard -Title "SQL Board" -Pages $pages -Navigation $Navigation -NavigationLayout Permanent -HeaderContent {
    New-UDButton -Text 'How to Guide' -Icon (New-UDIcon -Icon Users) -OnClick {
        Invoke-UDRedirect https://forums.ironmansoftware.com -OpenInNewWindow
    } -Color info
    New-UDButton -Text 'Create ticket' -Icon (New-UDIcon -Icon Book) -OnClick {
        Invoke-UDRedirect https://docs.ironmansoftware.com -OpenInNewWindow
    } -Color info
}

This is the Instances page:


$Columns = @(
    New-UDTableColumn -Property SQLInstanceName -Title "SQL Instance Name" -ShowFilter -ShowSort
    New-UDTableColumn -Property Active -Title "Active" -ShowSort
    New-UDTableColumn -Property DateAdded -Title "Date Added" -ShowFilter -ShowSort -SortType datetime
    New-UDTableColumn -Property SQLInstanceNameButton -Title "View" -Render { 
        New-UDButton -Text "View" -OnClick { 
            New-UDLink -Text $EventData.SQLInstanceName -url "/instance/:sqlid" -OpenInNewWindow
        } 
    }
)

New-UDGrid -Container -Content {
    New-UDGrid -item -SmallSize 12 -Content {
        New-UDCard -Title 'Select object type' -Content {
            New-UDStack -Direction 'column' -Content {
                $TableData = Invoke-DbaQuery -SqlInstance "dk1sqlclu01ag02" -Database "Atria" -Query "select SQLInstanceName,Active,DateAdded from SQLInstances"  
                
                New-UDTable -Id 'NameSelection' -Data $TableData -Columns $Columns -ShowPagination -PageSize 10 -ShowExport -ShowSort -Title "SQL Instances" -DefaultSortDirection ascending -DisableMultiSelect -HideToggleAllRowsSelected
            }
        }
    }
}

On the “Instances” page…

$Columns = @(
    New-UDTableColumn -Property SQLInstanceName -Title "SQL Instance Name" -ShowFilter -ShowSort
    New-UDTableColumn -Property Active -Title "Active" -ShowSort
    New-UDTableColumn -Property DateAdded -Title "Date Added" -ShowFilter -ShowSort -SortType datetime
    New-UDTableColumn -Property SQLInstanceNameButton -Title "View" -Render { 
        New-UDButton -Text "View" -OnClick { 
            New-UDLink -Text $EventData.SQLInstanceName -url "/instance/$($EventData.SQLInstanceName)" -OpenInNewWindow
        } 
    }
)

New-UDGrid -Container -Content {
    New-UDGrid -item -SmallSize 12 -Content {
        New-UDCard -Title 'Select object type' -Content {
            New-UDStack -Direction 'column' -Content {
                $TableData = Invoke-DbaQuery -SqlInstance "dk1sqlclu01ag02" -Database "Atria" -Query "select SQLInstanceName,Active,DateAdded from SQLInstances"  
                
                New-UDTable -Id 'NameSelection' -Data $TableData -Columns $Columns -ShowPagination -PageSize 10 -ShowExport -ShowSort -Title "SQL Instances" -DefaultSortDirection ascending -DisableMultiSelect -HideToggleAllRowsSelected
            }
        }
    }
}

So, when creating a page with a variable use…

New-UDPage -Name "mytitle" -URL "/mypath/:myvar"


#When redirecting to the page, use..

New-UDLink -url "/mypath/$myvar

Thanks for the continued help :slight_smile:
But i cant figure out, how to get the New-UDLink & New-UDPage working.

I ended up with this and i know the New-UDButton actually triggers the process - but nothing is happening.

$Navigation = @(
    New-UDListItem -Label "Home" -OnClick {
        Invoke-UDRedirect -Url '/home'
    }
    New-UDListItem -Label "Instances" -Children {
        New-UDListItem -Label 'All Instances' -Icon (New-UDIcon -Icon Microsoft) -OnClick {
            Invoke-UDRedirect -Url '/instances/all'
        }
    }
)

$Pages = @()
$Pages += Get-UDPage -Name 'Instances'
$Pages += New-UDPage -Name 'Home' -Content {
    New-UDGrid -Container -Content {
    }
}
$Pages += New-UDPage -Name 'Instance' -URL '/instance/:sqlid' -Content {
    New-UDLink -url "/instance/:sqlid"
}

  
New-UDDashboard -Title "Operations" -Pages $pages -Navigation $Navigation -NavigationLayout Permanent -HeaderContent {
    New-UDButton -Text 'How to Guide' -Icon (New-UDIcon -Icon Users) -OnClick {
        Invoke-UDRedirect https://forums.ironmansoftware.com -OpenInNewWindow
    } -Color info
    New-UDButton -Text 'Create ticket' -Icon (New-UDIcon -Icon Book) -OnClick {
        Invoke-UDRedirect https://docs.ironmansoftware.com -OpenInNewWindow
    } -Color info
}

$Columns = @(
    New-UDTableColumn -Property SQLInstanceName -Title "SQL Instance Name" -ShowFilter -ShowSort
    New-UDTableColumn -Property Active -Title "Active" -ShowSort
    New-UDTableColumn -Property DateAdded -Title "Date Added" -ShowFilter -ShowSort -SortType datetime
    New-UDTableColumn -Property SQLInstanceNameButton -Title "View" -Render { 
        New-UDButton -Text "View" -OnClick { 
            New-UDLink -Text $EventData.SQLInstanceName -url "/instance/$($EventData.SQLInstanceName)" -OpenInNewWindow
        } 
    }
)

New-UDGrid -Container -Content {
    New-UDGrid -item -SmallSize 12 -Content {
        New-UDCard -Title 'Select object type' -Content {
            New-UDStack -Direction 'column' -Content {
                $TableData = Invoke-DbaQuery -SqlInstance "dk1sqlclu01ag02" -Database "Atria" -Query "select SQLInstanceName,Active,DateAdded from SQLInstances"  
                
                New-UDTable -Id 'NameSelection' -Data $TableData -Columns $Columns -ShowPagination -PageSize 10 -ShowExport -ShowSort -Title "SQL Instances" -DefaultSortDirection ascending -DisableMultiSelect -HideToggleAllRowsSelected
            }
        }
    }
}