Dynamic Table shows maximum 2 entries only

Hi guys,

I’m reading group members from an AD group into a variable and want to load them into a dynamic table and display them. This works so far, but the table always only shows maximum two users, even though there are more. If I output the variable with write-output, all the group members are there, but the table still only shows two. I just don’t understand why.

Product: PowerShell Universal
Version: 5.5.3

Show your code where you have the issue. It’s easier to help if we can see what you are trying to do.

1 Like

I figured out where the problem lies.

The problem seems to be the array!

When I run the app for the first time and read a group that has 3 members, the table displays those 3 members. If I then read a group with fewer members, that’s no problem; they are also displayed. But if you then read a group with more than 3 members, a maximum of 3 members are displayed!

So the size of the table depends on the number of users to be displayed in the first run?! WTF!

So if I select a group that has, say, 50 members when I start the app for the first time, the table will only show a maximum of 50 results for subsequent queries

# Load the app theme
$Theme = Get-UDTheme -Name '1984'

New-UDApp -Title 'Suche' -Theme $Theme -Content {

    $SearchBase0 = "OU=abc,OU=xy,DC=DOMAIN,DC=LOCAL"
    $Filter = @('MYFILTER')
     $Alle = [pscustomobject]@{
    Name = 'Alle'
    }
    $OUs = @();
    $OUs += $Alle;
    $OUs += Get-ADOrganizationalUnit -SearchBase $SearchBase0 -SearchScope OneLevel -Filter * | Where-Object {$_.Name -notin $Filter} | Select-Object Name
        New-UDPaper -Elevation 0 -Content {
        New-UDTypography -Text "Blah?"
        }
    New-UDCard -Title 'Suche' -Content {

        New-UDSelect -Id "Auswahl" -MaxWidth '2000' -Option {
            foreach ($item in $OUs) {
                #Write-Host $item.Name
                New-UDSelectOption -Name $item.Name -Value $item.Name
            }
        } -OnChange {
                $DVGroup = @() 
                $Page:DVS = @()
                $SelectedAmt = (Get-UDElement -Id "Auswahl").value

                if ($SelectedAmt -eq $Alle.Name) {
                    $DVGroup = @(Get-ADGroup -Filter {Name -like "ABC-XYZ-123-B-*"} | Select-Object Name)
                } else {
                     $Name = "ABC-XYZ-123-B-"+$SelectedAmt
                    $DVGroup = @(Get-ADGroup -Filter {Name -like $Name} | Select-Object Name)
                }
                foreach ($item in $DVGroup){
                        $Members = @(Get-ADGroupMember -Identity $item.Name -ErrorAction SilentlyContinue | get-aduser -property * | Where-Object { ($_.Enabled -like $true)} | Select-Object Enabled, department, GivenName,Surname,sAMAccountName,mail,telephoneNumber,Mobile)
                }

                if (-Not($Members)){
					Sync-UDElement -Id 'dynTable'
                }
                else {
                    $Page:DVS += $Members
                    $length = $Page:DVS.length
                    Show-UDToast "$length" -BackgroundColor 'orange' -MessageSize '24' -Duration '5000' -CloseOnClick -Position 'center'
                    Sync-UDElement -Id 'dynTable'
                }
        }

    }

    New-UDCard -Title 'Tabelle' -TitleAlignment 'center' -Content {
		$Columns = @(
			New-UDTableColumn -Property department -Title "Department" -IncludeInExport -DefaultSortColumn
			New-UDTableColumn -Property Surname -Title "Nachname" -IncludeInExport -DefaultSortColumn
			New-UDTableColumn -Property GivenName -Title "Vorname" -IncludeInExport
			New-UDTableColumn -Property SamAccountName -Title "Anmeldekürzel" -IncludeInExport
			New-UDTableColumn -Property Mail -Title "Mail" -IncludeInExport
			New-UDTableColumn -Property telephoneNumber -Title "Telefon" -IncludeInExport
			New-UDTableColumn -Property Mobile -Title "Mobil" -IncludeInExport
		)
		New-UDDynamic -Id "dynTable" -Content {
			if ($Page:DVS){
				New-UDTable -Id "Test" -Columns $Columns -Data $Page:DVS -Sort -Dense -ShowSelection -OnRowSelection {Sync-UDElement -Id 'Selected'}
			}
		}
	}
} -LoadNavigation (Invoke-RestMethod -Uri $Hostname/Get-PSUNavigation -Method GET) -NavigationLayout permanent

Nice work finding the issue. I would suggest you read up on the scope variables to understand why you $page:DSV var might contain “old” data from a previous run.

In this case you might need to close down your tab and open a new one to get fresh data.

Here is the direct link to your live documentation:
https://YOURURL/apps/docs/Scopes

Or in your admin dashboard, click on Apps → Apps → Live Documentation Button

Thanks for your reply. Yeah, i have to learn a lot of thinks because everything is new to me.

No, the variable doesn’t contain any “old” or “invalid” data.
When I output the variable to the log, it contains exactly the data that should be output. But this data isn’t displayed in the table.

I’ve also built in a small counter that counts the array. It also displays the correct number.

$length = $Page:DVS.length
Show-UDToast "$length" -BackgroundColor 'orange' -MessageSize '24' -Duration '5000' -CloseOnClick -Position 'center'

But for some reason, the table is somehow limited to the number of users who are read first.

So if the first group only has 2 members and I then select another group in the select box that has 4 members, only 2 members are displayed in the table - even though the variable/array contains all 4?!

I dont get it! Sitting here for days on such a simple task!
This is not how I imagined it with powershell universal… :face_with_diagonal_mouth:

If I had to reload the page every time, why would I need a dynamic table? That would be completely insane.

I see what you mean. Using your code I am experiencing the same thing. If I have a 4 users group and change it to a different group with 10 users, It will only show 4 out of the 10 users in the table. So the first choice will always limit the number of rows visible in the table.

New-UDApp -Title "My Testing" -Content {

    
    function New-RandomUser {
        param($Index)

        $firstNames = @('Max', 'Julia', 'Anna', 'Lukas', 'Felix', 'Nina', 'Tim', 'Laura', 'Jan', 'Lea')
        $lastNames  = @('Müller', 'Schmidt', 'Schneider', 'Fischer', 'Weber', 'Meyer', 'Wagner', 'Becker')
        $departments = @('IT', 'HR', 'Sales', 'Finance', 'Logistics')

        $first = Get-Random $firstNames
        $last = Get-Random $lastNames
        $sam = "$($first.Substring(0,1).ToLower())$($last.ToLower())$Index"
        $mail = "$sam@example.com"
        $phone = "+49 89 1234 $((Get-Random -Minimum 1000 -Maximum 9999))"
        $mobile = "+49 171 $((Get-Random -Minimum 1000000 -Maximum 9999999))"

        [PSCustomObject]@{
            department      = Get-Random $departments
            Surname         = $last
            GivenName       = $first
            SamAccountName  = $sam
            Mail            = $mail
            telephoneNumber = $phone
            Mobile          = $mobile
        }
    }

    # Variable 1: 10 users
    $MockUsers10 = 1..10 | ForEach-Object { New-RandomUser -Index $_ }

    # Variable 2: 4 users
    $MockUsers4 = 1..4 | ForEach-Object { New-RandomUser -Index $_ }


    New-UDDynamic -Id "dynTable" -Content {

        New-UDSelect -Option {
            

            New-UDSelectOption -Name "10" -Value 10
            New-UDSelectOption -Name "4" -Value 4

        
        } -OnChange {
            Sync-UDElement "dynTable"

            IF ($eventData -eq "4") {

                $Page:DVS = $MockUsers4 

            }

            IF ($eventData -eq "10") {
                $Page:DVS = $MockUsers10
            }
        }

        New-UDCard -Title 'Tabelle' -TitleAlignment 'center' -Content {
            
                
                $Columns = @(
                    New-UDTableColumn -Property department -Title "Department" -IncludeInExport -DefaultSortColumn
                    New-UDTableColumn -Property Surname -Title "Nachname" -IncludeInExport -DefaultSortColumn
                    New-UDTableColumn -Property GivenName -Title "Vorname" -IncludeInExport
                    New-UDTableColumn -Property SamAccountName -Title "Anmeldekürzel" -IncludeInExport
                    New-UDTableColumn -Property Mail -Title "Mail" -IncludeInExport
                    New-UDTableColumn -Property telephoneNumber -Title "Telefon" -IncludeInExport
                    New-UDTableColumn -Property Mobile -Title "Mobil" -IncludeInExport
                )
                
                    if ($Page:DVS){
                        New-UDTable -Id "Test" -Columns $Columns -Data $Page:DVS -Sort -Dense -ShowSelection
                    }
                
            
        }
    }

}

I’ve created a simple version here that does not need AD to run. It had the same problem, right until I moved the new the new-dynamic to include the New-UDselection. So that seems to have fixed the problem for me.
Try and move your new-uddynamic to include new-udselection and it should also fix your issue. Give it a shot and let me know the outcome.