rali21
March 31, 2025, 2:35pm
1
Hello,
I’m trying to create UD Cards which have a unique onclick action when selected. I have a for loop that created the card but it only returns the value of the last card created.
foreach($item in $csvData){
$user = Get-ADUser -filter "EmployeeID -like '$($item.id)'" -Properties EmployeeID,Name
$users += $user
$Header = New-UDCardHeader -Avatar (New-UDAvatar -Content { "+" } -Sx @{ backgroundColor = "#f44336"}) -Title $item.id;
$title= $item.id
new-udcard -id "test" -Header $Header -Sx @{width="30%"} -OnClick{
Show-UDToast -Message $title -Duration 4000 -Position topCenter
}
}
Selecting any user there results in a toast with the T90007 Message.
Any ideas here would be helpful
Product: PowerShell Universal
Version: 4.5.2
Onclick action should be bound to the card id I suppose, try replacing -id "test"
with -id $item.id
(or no -id at all)
rali21
March 31, 2025, 4:12pm
3
So actually show-udtoast works as expected but I can’t change the card’s style properties
foreach($item in $csvData){
$user = Get-ADUser -filter "EmployeeID -like '$($item.id)'" -Properties EmployeeID,Name
$users += $user
$Header = New-UDCardHeader -Avatar (New-UDAvatar -Content { "+" } -Sx @{ backgroundColor = "#f44336"}) -Title $item.id;
$title= $item.id
new-udcard -id $item.id -Header $Header -Sx @{width="30%"} -OnClick{
Get-UDElement -Id $item.id | Set-UDElement -Attributes @{ style = @{ backgroundColor = "#D3D3D3" } }
Show-UDToast -Message $item.id
}
}
The above code prompts me for an element ID on the dashboard itself. Is there a different way to do this?
Check what data you can find in $eventdata or in $body inside the -onClick code block.
I usually try to display these to variables in a UDToast message like
message “$($body | out-string)”
Another “odd” thing I noticed, is that sometimes it seems that it helps to put a variable like
$myvar.whatever in parenthesis.
like - id ($myvar.whatever)
Hi,
as @PorreKaj mentioned, the onClick should be bound to the id of the element.
I tried as followed:
$Items = @(
@{
id = 1
text = "Test1"
}
@{
id = 2
text = "Test2"
}
@{
id = 3
text = "Test3"
}
)
foreach($Item in $Items) {
$Header = New-UDCardHeader -Title $Item.Text
New-UDCard -Id $Item.Id -Header $Header -OnClick {
Show-UDToast -Message "$($Item.Id) - $($Item.Text)" -Duration 5000 -Position topCenter
}
}
and it works, so you dont need the Get-UDElement part, only set the id of the New-UDCard.