Search code examples
vbscripthp-quality-center

How to extract Defects with linked TCs using QC OTA


I am successfully able to download the defects using the below code, but how to get the count of linked TCs with status 'Failed or Blocked' against each defect?

Sub GetDefectsByFilter()

On Error Resume Next
Dim a
Dim intIndex As Integer
Dim sngPercent As Single

Dim BugFactory, BugList, BgFilter
Dim Response As VbMsgBoxResult
Dim DefectID As String
If TDC Is Nothing Then ConnecttoQC
Set BugFactory = TDC.BugFactory
Set BgFilter = BugFactory.Filter
DefectID = frmDefectFilter.txtDefectID
BgFilter.Filter("BG_BUG_ID") = DefectID
Set BugList = BgFilter.NewList

Dim Bug, Row, Count As Integer
Count = 1
Row = 2
ActiveSheet.Cells(1, 1).Value = "Defect ID"
ActiveSheet.Cells(1, 2).Value = "Application"
ActiveSheet.Cells(1, 3).Value = "Status"

For Each Bug In BugList
    ActiveSheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
    ActiveSheet.Cells(Row, 2).Value = Bug.Field("BG_USER_06")
    ActiveSheet.Cells(Row, 3).Value = Bug.Field("BG_STATUS")
    Row = Row + 1
    Count = Count + 1
Next
frmDefectFilter.Hide
End Sub

Solution

  • Thanks @Roland. The below code snippet helped me.

    Sub ViewLinks()
    '------------------------------------------------------
    ' Output all bug links.
    
    Dim BugF As BugFactory, bList As List
    Dim aBug As Bug
    Dim bugL As ILinkable, LinkList As List, linkF As LinkFactory
    
       'tdc is the global TDConnection object.
    Set BugF = tdc.BugFactory
    Set bList = BugF.NewList("")
    
    For Each aBug In bList
    'Cast the Bug object to an ILinkable reference
    ' to get the link factory.
        Set bugL = aBug
        Set linkF = bugL.LinkFactory
        Set LinkList = linkF.NewList("")
        Dim SourceObj As Object, TargetObj As Object, InitObj As Object, lnk As Link
        Debug.Print: Debug.Print "---------------------------------"
        Debug.Print "Source Type"; Tab; "ID"; Tab; "Target Type"; _
            Tab; "ID"; Tab; "Initiated by"
        For Each lnk In LinkList
            With lnk
                Set SourceObj = .SourceEntity
                Set TargetObj = .TargetEntity
                Set InitObj = .LinkedByEntity
                Debug.Print TypeName(SourceObj); Tab; CStr(SourceObj.ID); _
                    Tab; TypeName(TargetObj); Tab; CStr(TargetObj.ID); _
                    Tab; TypeName(InitObj); Spc(3); InitObj.ID
            End With
        Next lnk
    Next aBug
    
    End Sub