Button click, read from hash

Ok, sorry for all the newbie questions. I have a hash table that i’m using to keep track of certain tasks throughout my singular page.

The idea is when a user checks a box, it adds an object to a hash table. Then I have another element, that when they hit a button, it’s supposed to look at all objects in the hash table and act on them.

Here is a really simplified example.

New-UDPage -Url “/$($Page_Name)” -Title $Page_Configuration.Title -ErrorAction Stop -Endpoint {
########################################################
#Parameters
$all_checked_users = @{} #empty hash to store checked users
#This section creats a check box for the user
Checkbox_Element = New-UDElement -Id ($CheckboxStateID) -Tag “span” -ErrorAction Stop
Checkbox = New-UDCheckbox -Id ($CheckboxID) -ErrorAction Stop -OnChange (
New-UDEndpoint -Endpoint {
########################################################
#UD endpoint params
$Employee_Object = $ArgumentList[0]
$CheckboxStateID = $null
$CheckboxID = $null
CheckboxStateID = "CheckBoxStateID_($Employee_Object.SamAccountName)"
CheckboxID = "CheckBoxID_($Employee_Object.SamAccountName)"
########################################################
#On click code
try
{
#Get the check box element
Log_Page_Message.message = "Getting ud element ID ($CheckboxID)"
Checkbox_Element_Temp = Get-UDElement -Id (CheckboxID) -ErrorAction Stop #Set the check box element set-UDElement -Id ($CheckboxStateID) -Content {$Checkbox_Element_Temp.Attributes[“checked”]} -ErrorAction Stop
#Add / remove user from has table
$ExistsInCheckedHash = all_checked_users."($Employee_Object.SamAccountName)"
If ($Null -eq $ExistsInCheckedHash)
{
$all_checked_users.Add($Employee_Object.SamAccountName , $Employee_Object)
}
Else
{
$all_checked_users.Remove(Employee_Object.SamAccountName) } #Sync the ud element state Sync-UDElement -Id (CheckboxStateID) -ErrorAction Stop } catch { Throw ($_.exception.message)
}
} -ArgumentList $Employee_Object
)

Now, that is supposed to add the ADobject to the hash table called “$all_checked_users”

Next, i create a simple button on the page that is trying to read that hash table.

New-UDButton -Text “Extend” -ErrorAction Stop -OnClick (
New-UDEndpoint -ErrorAction Stop -Endpoint {
if ($Null -eq $all_checked_users )
{
Show-UDToast -Message “Null” -BackgroundColor “Red” -Duration 5000
}
else
{
Show-UDToast -Message "Not null " -BackgroundColor “Green” -Duration 5000
}
}
)

TMK, the hash is populated, but when i click on the button, it always shows null. I know i can pass an argument list into the endpoint. But my concern is that i need to be able to clear out the master hash table after the button is clicked. I suspect if pass the argument, it will make a copy of the object rather than link back to the hash table defined in the middle of the page. is this an accurate assumpiton, and if so, is there any way to solve this problem.

Hope this isn’t too much code.

Now it’s working and i have no idea why :confused:

I’m glad it’s working, I just don’t know how it did. Anyway for now this can be ignored :slight_smile: