0

I have a LIST which contains many record's, I want to extract records based on a condition and if the condition satisfies then I need to add the condition satisfied record into a new list.

Below is the code which I have written till now:

Module Module2
Sub Main()
    Dim td
    td = CreateObject("TDApiOle80.TDConnection")
    td.InitConnectionEx("http://qc10dev/qcbin")
    'Note: For Quality Center, connect by using the URL below:
    'td.InitConnectionEx "http://<servername>:port/qcbin"
    td.ConnectProjectEx("DEFAULT", "GPS_PROGRAM", "PQRST", "XYX@123")
    Dim tsfact 'As TDAPIOLELib.TestSetFactory
    Dim tslist 'As TDAPIOLELib.List
    'Getting Random Test Set ID
    '************************ACCESS ALL THE TEST SETS ********************************************************************        '
    tsfact = td.TestSetFactory
    tslist = tsfact.NewList("")

    '************************GET THE COUNT OF TEST SETS ******************************************************************
    Dim Count_Of_TestSets
    Count_Of_TestSets = tslist.Count
    Console.WriteLine("Count of Test Sets" + Count_Of_TestSets.ToString)

    '************************GET A RANDOM TEST SET INDEX ***************************************************************  
    Dim TestSetID As Integer
    Dim TestSetName = Nothing
    Dim SerialNumber As Integer = 0
    Dim AttachmentPresent
    Dim tslist_Having_Attachments = Nothing

    For Each TestSet In tslist

        TestSetID = TestSet.ID
        TestSetName = TestSet.Name
        'Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
        AttachmentPresent = TestSet.HasAttachment()
        If StrComp(AttachmentPresent, "True") = 0 Then
            Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
        End If
    Next

    Console.WriteLine("Logic Completed, Press enter")
    Console.ReadLine()
    tslist = Nothing
    tsfact = Nothing
    td = Nothing
End Sub

End Module

If you go through the above code the base List is tslist.

From this tslist which ever records has satisfied condition StrComp(AttachmentPresent, "True") = 0

has to be added to New list say tslist_attachment.

How can create a new list and add the values?

Please let me know the steps,.

Regards, Srihari

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Srihari
  • 2,509
  • 5
  • 30
  • 34

2 Answers2

0

From your description, it seems that you want to have a list of all attachments. You want to do that by iterating the TestSet, see if it contains an attachment and if so, add it to a list.

This post on SQA Forums explains how you can directly retrieve the list of attachments from a given testset by using the TestSetTreeManager and retrieving a TestSet from it by node id. Then all attachment from this node can be gathered at once:

Snippet:

Set TestSetTreeManager = TDConnection.TestSetTreeManager
Set TestSetFolder = TestSetTreeManager.NodeById(provideId)
If TestSetFolder.HasAttachments Then    
    Set Attachment = TestSetFolder.Attachments  
    Set AttachmentList = Attachment.NewList(" ")
End if
AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47
0

Below is the Logic I have written to handle this :)

Module Module2
Sub Main()
    Dim td
    td = CreateObject("TDApiOle80.TDConnection")
    td.InitConnectionEx("http://qc10dev/qcbin")
    'Note: For Quality Center, connect by using the URL below:
    'td.InitConnectionEx "http://<servername>:port/qcbin"
    td.ConnectProjectEx("DEFAULT", "GPS_PROGRAM", "svanumu", "ABCD")
    Dim tsfact As TDAPIOLELib.TestSetFactory
    Dim tslist As TDAPIOLELib.List

    Dim Temporary_List As TDAPIOLELib.List = Nothing
    Temporary_List = New TDAPIOLELib.List()

    'Getting Random Test Set ID
    '************************ACCESS ALL THE TEST SETS **************************************************​******************        '
    tsfact = td.TestSetFactory
    tslist = tsfact.NewList("")
    '************************GET THE COUNT OF TEST SETS **************************************************​****************
    Dim Count_Of_TestSets
    Count_Of_TestSets = tslist.Count
    Console.WriteLine("Count of Test Sets" + Count_Of_TestSets.ToString)
    '************************GET A RANDOM TEST SET INDEX **************************************************​*************  
    Dim TestSetID As Integer
    Dim TestSetName = Nothing
    Dim SerialNumber As Integer = 0
    Dim AttachmentPresent
    'Dim tslist_Having_Attachments As TDAPIOLELib.TestSetFactory

    Dim TestSetID1 = Nothing
    Dim TestSetName1 = Nothing

    For Each TestSet In tslist
        TestSetID = TestSet.ID
        TestSetName = TestSet.Name

        AttachmentPresent = TestSet.HasAttachment()
        If StrComp(AttachmentPresent, "True") = 0 Then
            Temporary_List.Add(TestSet)
            'Console.WriteLine("TestSetID::" + TestSetID.ToString + "TestSetName::" + TestSetName + "is Added from temporary list")
        End If
    Next

    '************************GET THE COUNT OF TEST SETS IN THE TEMPORARY LIST **************************************************​****************
    Dim Count_Of_TestSets_In_Temporary_List
    Count_Of_TestSets_In_Temporary_List = Temporary_List.Count
    Console.WriteLine("Count_Of_TestSets_In_Temporary_​List" + Count_Of_TestSets_In_Temporary_List.ToString)
    Console.WriteLine("Logic Completed, Press enter")
    Console.ReadLine()
    tslist = Nothing
    tsfact = Nothing
    td = Nothing
End Sub

End Module

Regards, Srihari

Srihari
  • 2,509
  • 5
  • 30
  • 34