UDinputField did not capture $session or $cache variables

Hi Guys,

I need some input on this, been pulling my hair all day. Below is the snippet of codes in the page.

New-UDElement -Tag 'pre' -Content {
    xxx xxx
} -Endpoint {

    $policies = Get-UDAuthorizationPolicy

    if ( $policies -contains "Admin") {
        if ($null -eq $session:user_organization) {
            $session:user_organization = [IO.File]::ReadAllLines("D:\xxxx_xxxx_ORG.txt") 
        }
    }
}
New-UDInput -Content {

    New-UDInputField -Type select -Name organization -Placeholder "Select Organization" -Value $session:user_organization

} -Endpoint {
    xxxx
} 

What puzzles me is the select drop-down menu does not list the organization - it is empty. However, I can see the $session:user_organization is loaded in UD, and from admin console I can see the list of organization when queried. The same issue with $cache variable, I can see it is cached but not displayed in the drop down menu.

image

If I only declare this outside of the UDelement with cache variable it worked - this is how I normally do it. But I received a new request where I need to list organization based on user’s policy. Appreciate your input.

I have got it working with Sync-UDElement and New-UDElement. I guess all I need was to sleep on it and boom - solution! :smiley: