Get-UDElement not working 3.0 beta 7

I’ve created a New-UDForm that my user’s fill out.

OnSubmit I’m getting the values of the fields like:

$myValue = (Get-UDElement -Id 'myID').value

This works fine.

Now in order to avoid my users filling out the form multiple times with the same information I’ve added a “Copy” button that sets all the fields back to what they previously submitted like:

Set-UDElement -Id 'myID' -Properties @{value = 'test'}

This works in the sense that the user can see all the various input fields filled out. However, when the form is submitted the second time, the “Get-UDElement” method doesn’t work on the second submission. The values are coming up blank.

Anyone know what I am doing wrong or if this is just a bug?

The other issue I’ve noticed is when setting back values to textbox fields it doesn’t apply the “filled” css so the text ends up being covered by the label.

Thanks in advance,

Any ideas?

This looks like a bug.

One thing I would try to do, in terms of resetting the form, would be to wrap the form in a New-UDDynamic and call Sync-UDElement on that to cause it to totally recreate the form.

Would that achieve what you are looking for?

Hey Adam,

Yeah, that might work - I get what you mean. It’d take some finagling though since I basically have a form + a shopping cart and am initializing some values on form load that I would not want to reinitialize after their first submit.

One thing I did notice though, is I just updated to 1.3.1 on my development box and now the “Copy” button doesn’t work at all anymore, no code changes at all to my knowledge.

So if you think it is a bug that might be fixed in the near future i’d rather just wait and avoid shuffling all my code around but if it’ll be a few weeks I may have to do that.

Let me know if you want me to go make a bug on github.

Thanks,

Ok. I gotcha. I’ll throw this into our 1.3.2 bug fix release. It should be out in the next week or so.

Can you please check the browser console (F12) to see if there are any errors? I’m not seeing any issues with buttons in my 1.3.1 instance. Can you also check the dashboard log in the admin console?

Here are the errors I see on page load:

I do not see any additional errors produced when clicking my “Copy” button. The code is pretty basic:

(In a for each loop so every item in the shopping cart gets a “Copy” button)

                        New-UDButton -Text 'Copy' -OnClick {
                          Set-UDElement -Id 'vmWorkOrder' -Properties @{
                            value = $_.WorkOrder
                          }
                          ...
                          Set-UDElement -Id 'vmRAM' -Properties @{
                            value = $_.RAM
                          }
                              
                              
                        }

Edit: curious if it was a scoping issue I added a “Show-udtoast -message ‘bleh’” as the first item in the copy button code, that didn’t even fire.

Thanks,

It seems like it’s failing to render something. It’s a little hard to tell from the log. Can you make sure you clear your browser cache and try again?

One other thing I would suggest doing, that could be a scoping issue, is to avoid using the $_ variable in the OnClick event handler.

Just do something like:

$MyValue = $_
 New-UDButton -Text 'Copy' -OnClick {
                          Set-UDElement -Id 'vmWorkOrder' -Properties @{
                            value = $MyValue.WorkOrder
                          }
                          ...
                          Set-UDElement -Id 'vmRAM' -Properties @{
                            value = $MyValue.RAM
                          }
                              
                              
                        }

The problem is that sometimes PowerShell will stomp on the $_ variable when we try to set it and it will end up being $null.

Sorry for the late reply.

I get what you’re saying but that was not necessary at all in previous versions with the same code.

I actually found another spot where code that worked in (3.0.0-beta7) is now broken in 3.0.2. Same situation where I am using the $_ variable.

Cache shouldn’t be an issue here because when I say I “updated” I actually got a brand new laptop and installed the new version of Universal to what was essentially a virgin PC. Not to mention, I pretty much live the “Ctrl + F5” life.

I tried doing this and this isn’t working either:

                      New-UDIconButton -Icon (New-UDIcon -Icon times_circle) -OnClick {(New-UDEndpoint -Endpoint {
                        Show-UDToast -Message ('Removing {0}' -f $ArgumentList[0])
                        Remove-ADGroupMember -Identity 'mygroup' -Members $ArgumentList[0]
                        Sync-UDElement -Id 'adminCart'

                      } -ArgumentList $_.SamAccountName)
                      }

Button does not fire, nothing in the log.

I haven’t tried any of the newer nightlies, I may try that if you think it would be worth while.

@adam

Installed 1.4 this morning over the top but my dashboard, edited the properties of my existing dashboard and changed the framework version to 3.1.0 - now it won’t start at all.

I also notice significantly less output in the log and it seems to think it has started almost immediately but without any info in the log I’m not really sure of a direction to troubleshoot.

I tried stopping the service and deleting any of the older framework versions out of my c:\programdata directory but that didn’t seem to make a difference.

No errors in browser console either, this is all I see:

errror

I haven’t done any advanced debugging yet by attaching to the session or anything like that, i’ve been able to get by with the log up until this point.

Any suggestions?

Thanks,

Can you try getting a log out of %ProgramData%\PowerShellUniversal?

If there is anything you can share in terms of your dashboard PS1s, that would be helpful. You can always DM that to me or send via email.

I’ve just put some additional logging into this area that should help a little bit in diagnosing this in future builds from the dashboard log.

Thanks that log in programdata might have helpful info it looks like?

2020-09-22T09:24:39.4474035-07:00 0HM2V2G0BT2PO:00000001 [WRN] Error unprotecting the session cookie. (65f95c31)
System.Security.Cryptography.CryptographicException: The key {8e920a9a-eb39-4f45-a241-02cb709862dd} was not found in the key ring.
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
   at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)
2020-09-22T09:24:39.4475854-07:00 0HM2V2G0BT2PP:00000001 [WRN] Error unprotecting the session cookie. (65f95c31)
System.Security.Cryptography.CryptographicException: The key {8e920a9a-eb39-4f45-a241-02cb709862dd} was not found in the key ring.
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
   at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)

Let me know if that leads you any direction or not, if not I can see about sending some ps1s over.

Thanks for the quick reply

This error is likely not the issue. It happens when an old cookie is used with a new server but a new cookie should just be issued so it’s usually not a problem. You can try to clear your browser cookies to see if they makes that error go away. Some PS1s would likely be helpful.

I updated to the latest nightly again and checked that same log - see this now:

2020-09-23T10:14:36.4830711-07:00 0HM2VSG1J0G6S:00000014 [ERR] Failed to get dashboard (588ddaf8)
Grpc.Core.RpcException: Status(StatusCode=Unknown, Detail="Exception was thrown by handler.")
   at Universal.Server.Services.DashboardProxy.GetDashboard(Guid sessionId, String[] roles, String appToken)

Sending PS1 file is difficult since it is dependent on pulling data from SQL and AWS with creds.

Is there anything of note in the dashbaord log in the admin console? I’d be happy to schedule a call to see if we can figure this out together.

No, just like 4 lines instead of the normal 100+ I see. I’m paraphrasing here since I already switched to the older version but just like

Dashboard starting…
Dashboard started

I don’t see any of the “Loading Module” or “Loading Command” that I see in 3.0.0-beta7 e.g. none of this stuff:

[09-23-20 10:45:43 AM] Setting up runspace. 
[09-23-20 10:45:43 AM] Loading module: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\ActiveDirectory.psd1 
[09-23-20 10:45:43 AM] Loading module: C:\Program Files\WindowsPowerShell\Modules\AWSPowerShell.NetCore\4.1.0.0\ImportGuard.ps1 
[09-23-20 10:45:43 AM] Loading module: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1 
[09-23-20 10:45:43 AM] Loading module: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.psd1 
[09-23-20 10:45:43 AM] Loading module: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1 

I deleted the folders in c:\programdata then zipped up my working installation from my other machine, pasted that in my program files(x86) and started the service, works fine again.

So now I can switch back and forth pretty easily between versions to demonstrate this.

A call would be great - should I just email you at adam (at) poshtools?

Thanks,

Yep. Please email me at that address.