ALM Open Test Architecture API Reference Version 12.55
Check whether any item in the subject tree matches a filter
Public Function CheckForAnyMatch(reqID As Long) As HierarchySupportList

' Check whether any item in the subject tree matches a filter


'###############################################################
' This example shows the use of the IHierarchyFilter to check
' whether there are any requirements in the project that match
' a filter, by not specifying an ID for the root of the search.
'    Case A: There is at least one requirement that matches the filter
'    Case B: There is no requirement in the project that matches the filter
' 2) Finding which sub-trees under a specific requirement contain at least
'    one requirement that matches the filter.
'
' The example runs on a requirement tree with the requirements below.
' Each requirement has as ParentID the ID of the requirement one step
' above according to the numbers that are part of the name.
' For example, the ParentID of Grandson 1.1.1 is the ID of Child 1.1,
' and the ParentID of Grandson 1.4.1.1 is the ID of Son 1.4.1

' The first item, Req1, is the root of the search tree. The
' ReqID argument to this example is Req1.ID
'
' The fiter is:
'    Requirement.Name = "*Son* OR SubNode*" AND
'    Requirement.Product = "Emma OR 'Mansfield Park'"
' The items that match the filter in the example are marked with
' an asterisk.
'----------------------------------------------------------------------------
'    Name               | Description              | Priority    | Product
'----------------------------------------------------------------------------
'    Req1               | Root of search tree      | 2-Medium    | Persuasion
'    Child 1.1          | Child 1 of Req1          | 5-Urgent    | Persuasion
' *  Grandson 1.1.1     | GrandSon of Req1 1.1.1   | 2-Medium    | Emma
' *  Grandson 1.1.2     | GrandSon of Req1 1.1.2   | 2-Medium    | Emma

'    Child 1.2          | Child 2 of Req1          | 4-Very High | Mansfield Park
' *  Grandson 1.2.1     | GrandSon of Req1 1.2.1   | 5-Urgent    | Emma
'
'    Child 1.3          | Child 3 of Req1          | 3-High      | Persuasion
'    Child 1.3.1        | Grandchild of Req1 1.3.1 | 2-Medium    | Emma
'    Child 1.3.1.1      | GreatGrandChild of Req1 1.3.1.1
'                                                  | 2-Medium    | Mansfield Park
' *  GGGrndSon1.3.1.1.1 | Has Son in name          | 2-Medium    | Mansfield Park
'
'    Child 1.4          | Child 4 of Req1          | 2-Medium    | Northanger Abbey
'    Son 1.4.1          | GrandChild Req1          | 3-High      | Persuasion
'    Grandson 1.4.1.1   | Grandson of Req 1.4      | 5-Urgent    | Persuasion
'    Son 1.4.2          | Son 2 of Req 1.4         | 5-Urgent    | Persuasion
'
' *  Son 1.5            |Child 5 of Req1           | 3-High      | Emma


    Dim reqF As ReqFactory
    Dim hierFilter As HierarchyFilter
    Dim reqHierL As HierarchySupportList, reqL As List
    Dim rq As Req
    Dim i%
    
    On Error GoTo GetHListErr
    'tdc is the global TDConnection object.
    Set reqF = tdc.ReqFactory
    Set hierFilter = reqF.Filter

'  Get the parent nodes by setting KeepHierarchical = True.
'  Note that this setting is required to get
'  a HierarchySupportList. If KeepHierarchical
'  is False or not set, HierarchyFilter.NewList
'  returns a List, not a HierarchySupportList.
    hierFilter.KeepHierarchical = True
 
 
'''''''''''''''''''''''''''''''''''''''''''
' Case A: There is at least one requirement in the
'           project that matches the filter.
'
' To test all requirements, do not set any
' filter on RQ_FATHER_ID.
'''''''''''''''''''''''''''''''''''''''''


' Name filter matches "Son", "GrandSon", and "SubNode."
    hierFilter("RQ_REQ_NAME") = "*Son* OR SubNode*"
    
' Filter for the "Emma" or "Mansfield Park" projects.
'  Note that Mansfield Park must be quoted with straight quotes
'  because of the space between Mansfield and Park.
    hierFilter("RQ_REQ_PRODUCT") = "Emma OR 'Mansfield Park'"
        
' This fails if KeepHierarchical is not set to True:
    Set reqHierL = hierFilter.NewList
    
    Debug.Print "Number of records found is " & CStr(reqHierL.Count)
    'Output: Number of records found is 1
    
    For i = 1 To reqHierL.Count
        Set rq = reqHierL(i)
        With rq
            'Returns the root of the requirement tree,
            ' meaning, there is a least one requirement
            'that matches the filter.
            Debug.Print CStr(.ID) & ", " & .name
            'Output:
            '0, Requirements
        End With
    Next i

'''''''''''''''''''''''''''''''''''''''''''
' Case B: There is no requirement
'         in the project that matches the filter
'
' To test all requirements, do not set any
' filter on RQ_FATHER_ID.
'''''''''''''''''''''''''''''''''''''''''

'There are no items that match this condition:
    hierFilter("RQ_REQ_PRODUCT") = "'Pride and prejudice' OR 'Sense and Sensibility'"
    
    Set reqHierL = hierFilter.NewList
    
    Debug.Print "Number of records found is " & CStr(reqHierL.Count)
    'Output: Number of records found is 0
    
    Set CheckForAnyMatch = reqHierL

Exit Function
GetHListErr:
    On Error Resume Next
    Set CheckForAnyMatch = Null
End Function