Reference UD objects

I am trying to port automation front ends over to UD. Specifically, I’m building web forms to get details of a user request, trigger an automation, and return results.

UDInput is the obvious candidate, but the UDInputFields don’t have all of the required functionality. Other UD object have better functionality, but I don’t know how to reference them.

For example, the “select” UDInputField does not allow for multiple selections. UDSelect allows for multiple selections, but how do I reference the selected values? I read one forum topic where Adam explained that to use the value of UDSelect, I should add -OnChange code that sets a $Session scope variable. But how do I do that?

And then when the user clicks my “Execute” UDButton, after the automation is complete, how do I replace the form with the results? That is, how do I have UDInputAction like behavior if I’m not using an UDInput?

Similarly, next to that button, I need a “Cancel” button that takes the user to a specific page, and sometimes other buttons that take the user to other specific pages. How do I create buttons that act like links?

Thanks,
Tim Curwick

And using -OnChange to set a $Session variable may work for UDSelect, but what about something like UDTextBox, which does not have any event parameters?

Thanks,
Tim Curwick

Hey Tim,

You can use Get-UDElement to get the value of elements on the page. Here’s an example of getting the value of a textarea: https://github.com/ironmansoftware/ud-powershellexplorer/blob/master/src/pages/ast.ps1#L23

So the idea would be to create all your controls and then you can use Get-UDElement in your button’s OnClick handler to get the value of the elements there.

Adam,

I got Get-UDElement working in UniversalDashboard.Community v2.2, but the same code does not work in UniveralDashboard v2.2.

In UD.Community, Get-UDElement works in an -OnClick scriptblock, but not in an -Endpoint scripblock. Is that expected?

And I had another couple questions in my original post:

And then when the user clicks my “Execute” UDButton, after the automation is complete, how do I replace the form with the results? That is, how do I have UDInputAction like behavior if I’m not using an UDInput?

Similarly, next to that button, I need a “Cancel” button that takes the user to a specific page, and sometimes other buttons that take the user to other specific pages. How do I create buttons that act like links?

Thanks,
Tim Curwick

Adam,

On further testing, the difference is not UD.Community vs. UD.

On the machine I was using UD, I uninstalled it and installed UD.Community, and Get-UDElement still does not work on that machine.

I’ll start looking for differences between the two. Do you have any hints on what I should be looking for?

(And still please answer the other questions. :slight_smile: )

Thanks

Adam,

Both machines are running Windows 10 1803, so have the same Windows build, same .Net 4.7.2 build, same PowerShell 5.1 build.

This is the code that works on one machine, but not the other.

$DB = New-UDDashboard -Title 'Test Get-UDElement' -Content {

    New-UDTextbox -Id CopyFrom -Value 'Test1Value'

    New-UDButton -Text 'Click' -OnClick {
        $Session:CopyValue = ( Get-UDElement -Id CopyFrom ).Attributes.value
        Sync-UDElement -Id CopyTo }

    New-UDElement -Id CopyTo -Tag div -Endpoint {
        New-UDTextbox -Value $Session:CopyValue }
    }

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $DB -Port 1111

The machine where it doesn’t work is my client’s target device for a POC, so I need to get it working.

Any ideas why Get-UDElement doesn’t work on this machine?

Thanks,
Tim C

Adam,

Sorry, some debug logging showed that Get-UDElement is working. It’s the Session variables that are not.

This code works on machine A, but not on machine B. What could cause this? What should I be looking at?

$DB = New-UDDashboard -Title 'Test Session variable' -Content {

    New-UDButton -Text 'Click' -OnClick {
        $Session:MyVar = 'Potato'
        Sync-UDElement -Id OtherElement }

    New-UDElement -Id OtherElement -Tag div -Endpoint {
        $Session:MyVar | Out-File -FilePath "$Env:Temp\TestSessionVariable.txt" }
    }

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $DB -Port 1111

Thanks,
Tim C

Restarting the machine fixed both the Session variable issue and the Get-UDElement not working in an endpoint issue. (Restarting PowerShell had been insufficient.)

Both seem to be working normally now.

(I’ll re-ask the remaining questions in a different thread.)

Thanks,
Tim C

That’s very weird. I’m not sure why restarting the box would make then start working or why it was a problem to begin with.

There is an issue I’m looking into with Enable-UDLogging, otherwise I would usually suggest to get a log.