Okay really odd one here, cant quite work out what I’m doing wrong or if there’s a bug at play between versions.
I have an instance of universal locally installed which I setup a considerable time ago, installed as a service and running some sample code (i’ll post below) as a demo AD user picker.
Basically, I have a button, which created a modal popup, in which there’s a username search, which then triggers a sync on a dynamic element containing a table in the same modal, once the user is selected from that table, the modal closes and data from the selected user is displayed on the original page. It works as expected.
Universal 1.5.15
Dashboard Framework 3.3.4
I recently setup a new server, hosting the latest universal and dashboard framework in IIS.
Universal 2.4.1
Dashboard Framework 3.7.1
I copied over the exact same page & code.
On first use I get an error as shown:
but if I click out of my modal, and then go back in, it displays correctly.
Here’s the code:
$session:UserSelected = $Session:ADSearchResults = $null
New-UDTypography -Text "AD User Picker Test"
new-udhtml -Markup "<br>"
New-UDButton -Text 'Select User' -OnClick {
Show-UDModal -Header {"AD User Search"} -Content {
New-UDForm -Content {
New-UDTextbox -Id 'username' -Label "Username" -Placeholder "(exact)" -Autofocus
New-UDTextbox -Id 'firstname' -Label "First Name" -Placeholder "(Wildcard * allowed)"
New-UDTextbox -Id 'surname' -Label "Surname" -Placeholder "(Wildcard * allowed)"
} -OnSubmit {
$Session:ADSearchResults = $null
if($eventdata.username -notlike ""){
$Session:ADSearchResults = get-aduser -filter "samaccountname -eq '$($eventdata.username)'" -properties mail,department
}elseif($eventdata.firstname -notlike "" -or $eventdata.surname -notlike ""){
$filter = ""
if($eventdata.firstname -notlike ""){
$filter += "GivenName -like '$($eventdata.firstname)'"
}
if($eventdata.firstname -notlike "" -and $eventdata.surname -notlike ""){
$filter += " -and "
}
if($eventdata.surname -notlike ""){
$filter += "surname -like '$($eventdata.surname)'"
}
$Session:ADSearchResults = get-aduser -filter $filter -properties mail,department
}
$Session:ADSearchResults = $Session:ADSearchResults | %{
@{
avatar =""
name = $_.name
mail = $_.mail
department = $_.department
sid = $_.sid.value
}
}
Sync-UDElement -Id "DynamicADlookup"
}
New-UDDynamic -Id "DynamicADlookup" -Content {
New-UDTable -Id "ADSearchTable" -Data $Session:ADSearchResults -Columns @(
New-UDTableColumn -Property avatar -Title " " -Render { New-UDAvatar -Image $EventData.avatar}
New-UDTableColumn -Property Name -Title "Name" -DefaultSortColumn #-ShowFilter
New-UDTableColumn -Property mail -Title "Email" #-Render { New-UDLink -url "mailto:$($eventdata.mail)" -Text $eventdata.mail}
New-UDTableColumn -Property department -Title "Department"
) -OnRowSelection {
$session:UserSelected = $EventData
Sync-UDElement -Id "ADselection"
Hide-UDModal
} -ShowSelection
}
} -FullWidth -MaxWidth md
}
New-UDDynamic -Id "ADselection" -Content {
new-udhtml -markup "Selected User: $($session:UserSelected|convertto-json)"
}
The workaround I’ve managed to implement is as follows:
I can wrap the table with:
if(($Session:ADSearchResults | measure).count -gt 0){
Obviously that means that the empty table itself will not show on the page and will only pop in after the user hits submit - not an issue for me, but wondered if there’s a change in the way table data is handled between versions thats causing it to work okay in the earlier version but not in the later one?
Alternatively open to suggestions if theres a better way to do this, not worked with UD for a while so my brain is still geared to the ‘old’ way of doing things. Is it possible to refresh the table directly without the need for a new-uddynamic?
Thanks,
Tom