Create table from new-udselect

Trying to build a proof-of-concept dashboard using the select option to choose from a list of campuses and when one is selected the dhcp scopes for that campus will display. However the table is not being created Here is the code in question:

import-module dhcpServer
function get-campusScope {
param (
[Parameter(position=0,mandatory=$false)]
[string]$DhcpServer = “DHCPServer”,
[Parameter(position=1,mandatory=$true)]
$IpRange

)
try{

#$results = @()
$scopes = Get-DhcpServerv4Scope -ComputerName $DhcpServer | where-object {$_.ScopeId -like “$iprange*”}
$scopetable =foreach($Scope in $scopes){

Get-DhcpServerv4Lease -ComputerName $dhcpserver -ScopeId $scope.ScopeId |select-object IPaddress, ScopeID, ClientID, Hostname, AddressState, LeaseExpiryTime
#$results += $scoperesults

}

}
catch{

Write-Output “an error has occurred”

}
write-output $scopetable
}
$columns = @(
New-UDTableColumn -Property “IPaddress” -Title “Ipaddress” -showfilter
New-UDTableColumn -Property “ScopeID” -title “Scopeid”
New-UDTableColumn -Property “ClientID” -title “ClientID”
New-UDTableColumn -property “Hostname” -title “Hostname”
New-UDTableColumn -property “AddressState” -title “AddressState”
new-udtablecolumn -property “LeaseExpiryTime” -title “LeaseExpiryTime”

)
new-udselect -option {
New-UDSelectOption -name ‘Campus1’ -Value 1
New-UDSelectOption -name ‘Campus2’ -value 2
New-UDSelectOption -name ‘Campus3’ -value 3

} -id ‘Campus’ -Label “Select Campus” -OnChange{

$number = (Get-UDElement -Id ‘Campus’).value
Show-UDToast -Message $number

if ($number -eq “1”)
{

$iprange = “10.1”
Show-UDToast -Message $iprange
$tabledata = get-campusScope -IpRange $iprange

}
if ($number -eq “2”)
{

$iprange = "10.2
Show-UDToast -Message $iprange
$tabledata = get-campusScope -IpRange $iprange

}
if ($number -eq “3”)
{

$iprange = “10.3”
Show-UDToast -Message $iprange
$tabledata = get-campusScope -IpRange $iprange

}
Show-UDToast -Message $tabledata[1]
new-udtable -data $tabledata -Columns $columns -ShowPagination -PageSize 20

}

With out the select campus option it displays the specified campus correctly. Just looking for some help on where I went wrong.

Product: PowerShell Universal
Version: 3.4.4

I would wrap the table and logic to determine which option was selected, which data to load, etc, in a new-uddynamic. Then in the onchange of the udselect just use sync-udelement to sync the uddynamic.

that did the trick. thank you.