I have the following script that creates my missing groups in Orion:
#Creating a table with sites creation needed:
$GroupsToCreate = $allnbsites | Where-Object { $_.name -in $MissingGroups.DefinedEng } | Select-Object url, name, status, region, facility, physical_address, latitude, longitude
foreach ($gtc in $groupsToCreate) {
$BMR_Eng_Number = $gtc.Name
$groupName = $gtc.facility
$longitude = $gtc.Longitude
$latitude = $gtc.Latitude
#creating the group:
Invoke-SwisVerb $swis "Orion.Container" "CreateContainer" @(
# group name
$groupname,
# owner, must be 'Core'
"Core",
# refresh frequency
60,
# Status rollup mode: 0 = Mixed status shows warning, 1 = Show worst status, 2 = Show best status
0,
# group description
"Created by Provisioning Script (PL) v1.0",
# polling enabled/disabled = true/false (in lowercase)
$true,
([xml]"").DocumentElement)
#Getting newly group information:
$groupData = Get-SwisData $swis @"
SELECT gcp.ContainerID, g.Name, g.LastChanged, gcp.BMR_Eng_Number, gcp.BMR_Site_Type, gcp.Longitude, gcp.Latitude, gcp.LMRN_Description, gcp.LMRN_Zone, g.URI, CASE WHEN g.URI IS NOT NULL THEN CONCAT(g.URI,'/CustomProperties') ELSE NULL END AS CP_URI
FROM Orion.GroupCustomProperties gcp
LEFT JOIN Orion.Groups g on gcp.ContainerID = g.ContainerID
WHERE g.Name = '$groupname'
#Populating custom properties of the new group:
$CP = @{
"BMR_Eng_Number" = $BMR_Eng_Number
"Longitude" = $longitude
"Latitude" = $latitude
}
Set-SwisObject $swis $groupData.CP_URI $CP
# Creating dynamic to populate group:
$members = @(
@{ Name = "BMR_Eng_Number is $BMR_Eng_Number"; Definition = "filter:/Orion.Nodes[CustomProperties.BMR_Eng_Number=$BMR_Eng_Number]" }
)
Invoke-SwisVerb $swis "Orion.Container" "AddDefinitions" @(
# group ID
$groupData.ContainerID,
# group member to add
([xml]@(
"",
[string]($members | % {
"$($_.Name)$($_.Definition)"
}
),
""
)).DocumentElement
) | Out-Null
}
This is mostly inspired by https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/Groups.ps1
As expected, the groups gets created properly, the groups has the custom properties assigned, and a dynamic Query is attached to the group.
My problem is that once created, the dynamic query has no effect and does not populate the group.
If I go and look group properties, and click on "View Dynamic Query Results", I have a never ending spinning wheel:

To fix this issue, I found that if i click on "Edit Dynamic Query", and click Save right away, I can then click on "View Dynamic Query Results" and the expected nodes are there!!

Not sure if it is an API issue or a platform one... Am I missing something?
Running: Orion Platform HF2, UDT HF2, NCM HF1, NPM HF2, SAM HF2, NTA HF1: 2020.2.6