Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Honored Contributor.. arichtman Honored Contributor..
Honored Contributor..
79 views

Get all objects under a folder

Hi ALM-ers,

I'm trying to get ALL entities under a given folder - I'm just a bit confused about TestLabFolderFactory, TestSetTreeManager, TestSetFactory and how to get ALL nodes under a folder [tests, test sets, folders, etc].

0 Likes
1 Reply
Honored Contributor.. arichtman Honored Contributor..
Honored Contributor..

Re: Get all objects under a folder

Ok so I was able to get all test instances and remove those - now my problem is to find test sets with no instances. The property "ChildrenCount" that is returned doesn't seem to include the test instances?

$alm_uri = "http://alm/qcbin"
$uri = "$alm_uri/api/authentication/sign-in"

#region auth headers
$User_Pass  = $logon + “:” + $password
$bytes= [System.Text.Encoding]::UTF8.GetBytes($User_Pass)
$encoded_login=[Convert]::ToBase64String($bytes)
$Auth_Header = "Basic " + $encoded_login
$headers = @{}
$headers.Add("Authorization",$Auth_Header)
#endregion

#Log in
Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -SessionVariable web_session

#Get recycle bin target cycle ID 
$Response = Invoke-RestMethod -Method GET -WebSession $web_session -Uri "$alm_uri/rest/domains/$Domain/projects/$Project/release-cycles?fields=id&query={name[='Recycle Bin']}"
If($Response.Entities.TotalResults -ne 1){
    Throw 'Unexpected results when finding cycle'
}
$CycleId = $Response.Entities.Entity.Fields.Field.Value
#Get instances with target cycle Recycle Bin with VTS > 30 days -remove
$PastDate = Get-Date -Format 'yyyy-MM-dd 00:00:00'

$Response = Invoke-RestMethod -Method GET -WebSession $web_session -Uri "$alm_uri/rest/domains/$Domain/projects/$Project/test-instances?fields=id&query={assign-rcyc[$CycleId];last-modified[<='$PastDate']}"

$InstanceIds = Select-Xml -Xml $Response -XPath '//Field[@Name="id"]/Value' | %{$_.Node."#text"}

Foreach($InstanceId in $InstanceIds)
{
    $Response = Invoke-RestMethod -Method Delete -WebSession $web_session -Uri "$Alm_Uri/rest/domains/$Domain/projects/$Project/test-instances/$InstanceId"
}
#Get all test sets with target cycle Recycle Bin and 0 test instances - remove  

$Response = Invoke-RestMethod -Method GET -WebSession $web_session -Uri "$alm_uri/rest/domains/public/projects/2019_Q1_Q2/test-sets?fields=id&query={assign-rcyc[$CycleId]}"
#test instances in set don't show under childrencount....
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.