Dynamically generate UDGrid based on UDInput variable (or two)

I am trying to build a self-service reporting tool for non-technical end-users. The data source is basically a relational database (oracle). Depending on the need, users may want to get data based on one or two variables. This will definite the where parameters for the Select statement. (i.e. Select * from Students where schoolid = 3 and grade_level = 9)

  1. I am having trouble passing the variables from UDInput(s) to UDGrid at run-time. I don’t know which variables the users will choose to use, if one or both (or even more than that).

  2. I can only pass a variable if i nest a UDGrid inside a UDInputAction, but that means upon clicking submit, the input field disappears.

  3. In addition, depending on the parameters, the headers of the grid may have to change in runtime. How do i do this?

So in the UDInputs endpoint block, you have som code that querys a database based on the inputs, correct?

One way to solve all 3. would be to store the data from the query in a $Session: variable (like $Session:Data).

Then in the Grid, simply reference that variable, like

$Session:Data | Out-UDGridData

Right? now, I find autorefreshing Grids to be a pain (because it messes with the filtering).
Instead, give your Grid an -id (-id "OracleGrid"), and place Sync-UDElement -Id "OracleGrid" -Broadcast
in the UDInput’s Endpoint block, after storing data in the variable

Whatever you store in a $Session: variable, is stored there for that particular session, If you want site-wide you can use $Cache:

The Active Directory Dashboard on the Marketplace has a ‘Search page’ which uses another way of searching AD based on input, and then turning a UD element into a grid containing the data - this way the grid will remain hidden until something is searched.:

I have been using $Script:variablename

In the code below I get a dataset back then use it to present a chart and then a grid using subsets of th data returned

New-UDPage -Name “$DeploymentID” -Icon home -Content {
$Script:CollectionName = $CollectionName
$Script:DeploymentID = $DeploymentID
$Script:PackageID = $PackageID
$Script:ServerInstance = $ServerInstance
$Script:Database = $Database
$Script:LastHours = $LastHours

    $Script:Results = Get-DeploymentDetailsSQL -AdvertisementID $DeploymentID -PackageID  $PackageID -ServerInstance $ServerInstance -Database $Database -LastHours $LastHours |
                        Sort-Object -property Computername 

    $Script:SQLReportedMaxSteps = ($Results |
                           Where-object -property LastStatusMsgID -eq 11143  |
                           Sort-Object -property step -descending |
                           Select-Object -Property  Step -First 1).step
        if ($SQLReportedMaxSteps) {
        else {
            $SQLReportedMaxSteps = "No device has completed a build yet to know the number"  

        New-UDChart -Type HorizontalBar -AutoRefresh -RefreshInterval 30  -Title "$CollectionName Deployment  (Max Steps = $SQLReportedMaxSteps)" -Endpoint {
            $results|   Out-UDChartData -LabelProperty "Computername" -DataProperty "Step" -DatasetLabel "Deployment Progress"
        } -Options @{
            scales = @{
                xAxes = @(
                        ticks = @{
                            beginAtZero = $true

        New-UdGrid -Title "$CollectionName Deployment $DeploymentID Details" -AutoRefresh -RefreshInterval 30 -Endpoint {
            Select-object Computername,ExecutionTime,Step,GroupName,ActionName,ExitCode,LastStatusMsgName,LastStatusMsgID |
            Sort-Object -Property Computername    |  Out-UDGridData 

I’ll taker a deeper look at it once I get coffee. But just taking a quick look I see that you put the variables in the -content block of a new-udpage this means that the code is only run once, when the Dashboard is started. If that’s
the intention. then cool, but that means restarting the Dashboard for new data :slight_smile:

If I’m not mistaken, then I believe $Script: variables survives beyond the endpoint it’s defined. I would have been using $Session: instead.

Maybe a dynamic page fits your need better. It is described under Pages in the docs.


So you could have something like this:

New-UDPage -Url "/myPage/:DeploymentID" -Endpoint {


Then when you visit Dashboard.domain.com/MyPage/TEST
“TEST” will be available on that page inside the $DeploymentID variable.

Since this is a dynamic page, thus using an Endpoint block for the content, the page is build when visited and you use that to, well, do whatever :slight_smile:

Thanks everyone, i appreciate the assistance. I’ll give it a try once i have the chance.

I tried to change the scope of the variable, but that didn’t work. Not sure what I’m doing wrong. Do I need to create it first before assigning a value to it?

I used script, session and even global.