TiX
September 16, 2020, 12:48pm
1
Hi there, I have a problem to get the value from UDSelect. The $Body shows the correct value,
but with (Get-UDElement -Id ‘abc123’).value the $value is still null…
what am I doing wrong?
Thanks for your help!!!
New-UDGrid -Container -Content {
New-UDGrid -Item -ExtraSmallSize 12 -Content {
New-UDPaper -Content {
New-UDSelect -Id 'abc123' -Option {
foreach($line in Get-Content 'xxxxxxxxx.txt'){
New-UDSelectOption -Name $line -Value $line
}
} -OnChange { Show-UDToast -Message $Body}
} -Elevation 2
$value = (Get-UDElement -Id 'abc123').value
New-UDButton -Text 'TestValue' -OnClick {Show-UDToast -Message $value}
}
}
adam
September 16, 2020, 12:49pm
2
Try this syntax:
$value = (Get-UDElement -Id 'abc123')["Value"]
TiX
September 16, 2020, 12:57pm
3
thank you for your response, i used your described syntax, but the following error occurred
It is not possible to apply an index to a NULL array
adam
September 16, 2020, 1:13pm
4
Looks like you are calling Get-UDElement before the select is rendered. Try this.
New-UDGrid -Container -Content {
New-UDGrid -Item -ExtraSmallSize 12 -Content {
New-UDPaper -Content {
New-UDSelect -Id 'abc123' -Option {
foreach($line in Get-Content 'xxxxxxxxx.txt'){
New-UDSelectOption -Name $line -Value $line
}
} -OnChange { Show-UDToast -Message $Body}
} -Elevation 2
New-UDButton -Text 'TestValue' -OnClick {
$value = (Get-UDElement -Id 'abc123')["value"]
Show-UDToast -Message $value
}
}
}
1 Like
TiX
September 16, 2020, 1:38pm
5
thank you so much!!! it works
Hello, I have a similar problem with getting data from UDSelect. What I am attempting to do is extract an AD computer (hashtable) from the UDSelect field in the second of two stepper steps. It looks to me like the supported method of extraction is by using the -OnChange parameter. After a ton of fussing, I proved that the -Onchange script block is not running.
What am I doing wrong?
Take a look at my code below:
New-UDStepper -Steps {
#Step 1
New-UDStep -OnLoad {
New-UDTextbox -Id 'compName' -Label "Computer name:"
} -Label "Search"
#Step 2
New-UDStep -OnLoad {
$value = $body | ConvertFrom-Json
$value = $value.context.compName
$computers = Get-ADComputer -Filter "Name -like ""$value*""" -Properties 'ms-Mcs-AdmPwd' -SearchBase "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
New-UDPaper -Content {
New-UDSelect -Id 'compSelect' -Option {
foreach($computer in $computers){
New-UDSelectOption -Name $computer.Name -Value $computer
}
} -OnChange { $Session:computer = (Get-UDElement -Id 'compSelect')['Value']}
}
} -Label "Computer Selection"
} -OnFinish {
$LapsPwdAttrName = 'ms-Mcs-AdmPwd'
$password = $Session:computer.$LapsPwdAttrName
New-UDTypography -Text "Computer: $($Session:computer.name)" -Variant "body1"
New-UDTypography -Text "Distinguished Name: $($Session:computer.DistinguishedName)" -Variant "body1"
New-UDTypography -Text "Password: $password" -Variant "body1"
}