When the function in Globals.ps1 runs, the correct number of entries is populated in the array.
- function GetGridProfiles()
- {
- Write-Verbose "------ Fn: Get Grid Profiles ------"
- $arrayProfiles = @()
- (Get-ChildItem -Path HKCU:\Software\gotomyerp\Configurator\Profiles) | ForEach-Object {
- $RegPath = $($_.Name).Replace("HKEY_CURRENT_USER", "HKCU:")
- $Company = Get-ItemPropertyValue -Path $RegPath -Name Company
- $FeedURL = Get-ItemPropertyValue -Path $RegPath -Name FeedURL
- $Username = Get-ItemPropertyValue -Path $RegPath -Name Username
- $arrayProfiles += "$_.Name|$Company|$FeedURL|$Username"
- Return $arrayProfiles
- }
- Write-Verbose "Array Profiles after GetGridProfiles is done: $($arrayProfiles)"
- Write-Verbose "Array Size after GetGridProfiles is done: $($arrayProfiles.GetUpperBound(0))"
- }
- # Build the Grid PS Object
- Write-Verbose "Building the Grid PS Object"
- $arrayObjProfiles = @()
- Write-Verbose "Type : $($arrayObjProfiles.GetType().BaseType.Name)"
- $aProfileList = GetGridProfiles
- Write-Verbose "aProfileList Index: $($aProfileList.GetUpperBound(0))"
- Write-Verbose "aProfileList: $($aProfileList))"
- foreach ($Profile in $aProfileList)
- {
- $FeedID = ($Profile.Split("|"))[0]
- $Company = ($Profile.Split("|"))[1]
- $FeedURL = ($Profile.Split("|"))[2]
- $DisplayURL = (($FeedURL).split("/"))[0] + "//" + (($FeedURL).Split("/"))[2]
- $Username = ($Profile.Split("|"))[3]
- $CurrentObject = [PSCustomObject]@{
- Company = $Company
- DisplayURL = $DisplayURL
- Username = $Username
- }
- $arrayObjProfiles += $CurrentObject
- Write-Verbose "Type inside: $($arrayObjProfiles.gettype().BaseType.Name)"
- }
- Write-Verbose "arrayObjProfiles outside the loop: $($arrayObjProfiles.GetType().BaseType.Name)"
Here is an output of the script when those 2 blocks of code run:
>> Running (gotomyerp Configurator.psproj) Project Script... >> Platform: V5 32Bit (STA) (Forced) VERBOSE: ------ Startup: Getting Workspace Feeds ------ VERBOSE: ------ Startup: Loading cmdkeys - Getting username ------ VERBOSE: ------ Startup: Getting Company from registry ------ VERBOSE: ------ Fn: Check and Set Registry Base ------ VERBOSE: ------ Btn: LoadProfiles Click ------ VERBOSE: Building the Grid PS Object VERBOSE: Type : Array VERBOSE: ------ Fn: Get Grid Profiles ------ VERBOSE: Array Profiles after GetGridProfiles is done: HKEY_CURRENT_USER\Software\gotomyerp\Configurator\Profiles\E44DDD5C-BD2E-4B54-8802-8874A7CED0A0.Name|client2|https://client2.example2.com/rdweb/feed ... d.aspx|cpt HKEY_CURRENT_USER\Software\gotomyerp\Configurator\Profiles\E5E475EA-E135-4EE4-B81B-D1E107B50302.Name|client1|https://client1.example1.com/rdweb/feed ... px|qbdemo1 VERBOSE: Array Size after GetGridProfiles is done: 1 VERBOSE: aProfileList Index: 2 VERBOSE: aProfileList: HKEY_CURRENT_USER\Software\gotomyerp\Configurator\Profiles\E44DDD5C-BD2E-4B54-8802-8874A7CED0A0.Name|client2|https://client2.example2.com/rdweb/feed ... d.aspx|cpt HKEY_CURRENT_USER\Software\gotomyerp\Configurator\Profiles\E44DDD5C-BD2E-4B54-8802-8874A7CED0A0.Name|client2|https://client2.example2.com/rdweb/feed ... d.aspx|cpt HKEY_CURRENT_USER\Software\gotomyerp\Configurator\Profiles\E5E475EA-E135-4EE4-B81B-D1E107B50302.Name|client1|https://client1.example1.com/rdweb/feed ... px|qbdemo1) VERBOSE: Type inside: Array VERBOSE: Type inside: Array VERBOSE: Type inside: Array VERBOSE: arrayObjProfiles outside the loop: Array VERBOSE: ------ Form: Load Profile ------ VERBOSE: arrayObjProfiles after the loop:Note the 2 highlighted lines in the output. These are consecutive lines, but yet returning different array lengths.
I have checked that there are no other "OnLoad" events or similar in my forms that could trigger the array to be mis-populated.
Another interesting tidbit, is that before I moved this code to my current project (with multiple forms), I had both the function and the event code running in a single psf file (For testing), and it worked as expected. So I'm inclined to think that the issue might be somewhere between the forms being loaded/called.
Along the same lines, the $arrayObjProfiles array is also not populating in the multi-form project, but is working ok on my testing psf.
I have spent over 3 hours trying to figure it out, and I'm really stuck. This is my first forms project, so, please go easy on me
Would appreciate any guidance that could get me back on track.
Cheers!