Added update in later comment here: Returning a grid from a function
I’m trying to run some functions and have them return a grid object in to a card. If I run everything manually in a console and then start the dashboard or if I get rid of the functions and do everything explicitly in an endpoint it works.
It is returning a grid object but it is empty (however it returns the $proof
from the second function meaning it did actually retrieve the data.
Here’s what the output looks like, the 6 is an arbitrary piece of data from the grid.:
Here is the dashboard I’m trying to run (in the .ps1, the functions are defined above the start of this code):
$x = New-UDEndpointInitialization -Function @("New-SNIncidentTable","New-SNResponse")
$Dash = New-UDDashboard -Title "Monitoring System" -EndpointInitialization $x -Content {
New-UDCard -Endpoint {
$x = New-SNIncidentTable #This function returns a UDGrid
$x}
}
Start-UDDashboard -Dashboard $Dash -port 1000
Here’s the code I’m using for the first function, this gets a response from a URI and returns it as json. The other function returns the New-UDGrid
function New-SNResponse {
param($URI)
$user = "somename"
$pass = "somepass"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify HTTP method
$method = "get"
$body2 = {request.body ? "$body = `"" :""}
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri
# Convert Result
$JSONResponse = ($response.Content | ConvertFrom-Json).result
Return $JSONResponse
}
Here’s the code for the second function:
function New-SNIncidentTable {
$uri = "https://somedomain.service-now.com/api/now/table/incident?sysparm_display_value=true&sysparm_limit=1000&sysparm_query=active%3Dtrue%5EstateNOT%20IN730%2C3%5Eassignment_group%3D361ec2626f14ba0039d3dd1cbb3ee406"
$OpenIncidents = New-SNResponse -URI $uri
#Process and store results
$IncidentData = @()
Foreach ($Incident in $OpenIncidents) {
$IncID = $Incident.Number
$IncImpact = $Incident.Impact
$IncPriority = $Incident.priority
$IncShortDescription = $Incident.short_description
$IncPrivacy = $Incident.u_notify_privacy
$IncLastUpdated = $Incident.sys_updated_by
$IncCreated = $Incident.sys_created_on
$IncSubcategory = $Incident.subcategory
$IncUrgency = $Incident.urgency
$IncStatus = $Incident.State #730 = Resolved, 2 = In Progress, 1 = New
$IncidentInfo = @{ID = $IncID}
$IncidentInfo["Short Description"] = $IncShortDescription
$IncidentInfo["Impact"] = $IncImpact
$IncidentInfo["Priority"] = $IncPriority
$IncidentInfo["Urgency"] = $IncUrgency
$IncidentInfo["Privacy Incident"] = $IncPrivacy
$IncidentInfo["Created"] = $IncCreated
$IncidentInfo["Last Updated"] = $IncLastUpdated
$IncidentInfo["Subcategory"] = $IncSubcategory
$IncidentInfo["Status"] = $IncStatus
#Add to array
$IncidentData += $IncidentInfo
}
$proof = $openIncidents.count
#Turn data in to a grid
$GridOutput = New-UDGrid -Title "$proof" -Headers @("ID","Short Description","Impact","Priority","Urgency","Privacy Incident","Created","Last Updated","Subcategory","Status") -Properties @("ID","Short Description","Impact","Priority","Urgency","Privacy Incident","Created","Last Updated","Subcategory","Status") -Endpoint {
$IncidentData | Out-UDGridData
}
Return $GridOutput
}
Any help would be amazing! Thanks