New-UDPage -Url "/AppNameLookup" -Name "AppNameLookup" -Content {
New-UDTypography -Id "disclaimer" -Text "This is querying the cmdb_ci_service_auto table in ServiceNow.  This is live data being shown."


New-ITDServiceNowSession -Environment Production -Credential $Secret:snow_vmcred
    $PropertyList = @(
        @{
            name       = "name";
            expression = { $_.name.display_value };
        },
        @{
            name       = "sys_id";
            expression = { $_.sys_id.value } ;
        },
        @{
            name       = "u_primary_systems_admin";
            expression = { $_.u_primary_systems_admin.display_value } ;
        },
        @{
            name       = "u_secondary_systems_admin";
            expression = { $_.u_secondary_systems_admin.display_value } ;
        },
        @{
            name       = 'u_systems_owner';
            expression = { $_.u_systems_owner.display_value};
        }
    )
    #$Result = Get-ITDServiceNowRecord -Table cmdb_ci_server -Filter ("nameLIKE" + $EventData.CiName) -IncludeTotalCount | Select-Object -Property $PropertyList
    $GetITDServiceNowRecordParams = @{
            Table             = 'cmdb_ci_service_auto';
            IncludeTotalCount = $true;
            Fields            = @(
                'name',
                'sys_id',
                'u_primary_systems_admin',
                'u_secondary_systems_admin',
                'u_systems_owner'
            )
        }
    $Result = Get-ITDServiceNowRecord @GetITDServiceNowRecordParams | Select-Object -Property $PropertyList
    $CmdbCiUrl = "https://northdakota.service-now.com/nav_to.do?uri=" + $Result.sys_class_name + ".do?sys_id=" + $Result.sys_id

    New-UDTable -Columns @(
        New-UDTableColumn -Property 'SNowUrl' -Title 'CmdbCiUrl' -Render { #https://northdakota.service-now.com/nav_to.do?uri=cmdb_ci_win_server.do?sys_id=8bc3ecd11b0154509d7ada01dd4bcb59
            New-UDLink -Url ("https://northdakota.service-now.com/nav_to.do?uri=cmdb_ci_service_auto.do?sys_id=" + $EventData.sys_id) -Id "lnkSNow" -Content {
                New-UDImage -Url "https://psuniversal.nd.gov/PSUniversal_Extras/servicenow_logo_icon_168835.png" -Height 20 -Width 20
            }
        }
        New-UDTableColumn -Property 'name' -Title 'name' -ShowSort -ShowFilter
        #New-UDTableColumn -Property 'sys_id' -Title 'sys_id' -ShowSort -ShowFilter
        New-UDTableColumn -Property 'u_primary_systems_admin' -Title 'u_primary_systems_admin' -ShowSort -ShowFilter
        New-UDTableColumn -Property 'u_secondary_systems_admin' -Title 'u_secondary_systems_admin' -ShowSort -ShowFilter
        New-UDTableColumn -Property 'u_systems_owner' -Title 'u_systems_owner' -ShowSort -ShowFilter
    ) -Data ($Result | sort-object Name) -ShowPagination -Dense -PageSize 50
} -Title "AppNameLookup" -Icon @{
		id = '9fdceac8-807e-4d5e-acda-3d477d77fdb4'
		type = 'icon'
	}