Download all attachments from HP ALM Test Plan

I need to download all the attachments from all the tests within the test plan. I have a function that should do that and I need some advice with it.

I have posted the function that I have used to get all the attachments. I have tried retrieving the attachments based on a path that is given. I have tried changing the filter based on values I have found in the CROS_REF table, CR_REFERENCE field.

Public Function DownloadAttachments(TDFolderPath, sDownloadTo)
Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
Dim otaAttachment 'As TDAPIOLELib.Attachment
Dim otaAttachmentList 'As TDAPIOLELib.List
Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
Dim otaTreeManager 'As TDAPIOLELib.TreeManager
Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")
Dim strPath 'As String
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath) Set otaAttachmentFactory = otaSysTreeNode.Attachments Set otaAttachmentFilter = otaAttachmentFactory.Filter otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_*'" Set otaAttachmentList = otaAttachmentFilter.NewList DowloadAttachments = "" If otaAttachmentList.Count > 0 Then For i = 1 to otaAttachmentList.Count
set otaAttachment = otaAttachmentList.Item(i)
otaAttachment.Load True, "" If (fso.FileExists(otaAttachment.FileName)) Thens
= otaAttachmentList.Item(i).Name myarray = split(strFile,"ALL_LISTS_"& otaSysTreeNode.NodeID & "_")
fso.CopyFile otaAttachment.FileName, sDownloadTo & "\" & myarray(1)
Reporter.ReportEvent micPass, "File Download:", myarray(1) & " downloaded to " & sDownloadTo DownloadAttachments = sDownloadTo
end if Next Else
Reporter.ReportEvent micFail, "No attachments to download", _"No attachments found in specified folder '" & TDFolderPath & "'."DowloadAttachments = "Empty" End If Set otaAttachmentFactory = Nothing Set otaAttachment = Nothing Set otaAttachmentList = Nothing Set otaAttachmentFilter = Nothing Set otaTreeManager = Nothing Set otaSysTreeNode = Nothing Set fso = nothing End Function

 Regardless of what (valid) path I have tried, the result is the same. It says that there are no attachments to download. I`m pretty sure the issue is in this piece of code:

Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_*'"

 Also, if anyone has any advice over other approaches, any help would be gladly appreciated! Thank you

  • Have you fixed this typo? 

    If (fso.FileExists(otaAttachment.FileName)) Thens

    Can you confirm that QCUtil is available in this scope? Are you sure you need to specify .TDConnection again?

    Set otaTreeManager = QCUtil.TDConnection.TreeManager
  • Hello arichtman 

    The typo has been fixed, yes (in fact it was an autocorrect issue form the forum)

    For the second question, yes, QCUtil is available in the scope.


    My issue is somewhere at the filtering part, and I can't figure out what is not working properly..

    Thank you for your time!


  • Try removing this line and checking the count of newlist - this will confirm we have objects to return when filtered.

    otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_*'"

    If the count is >0 then maybe run NewList() and loop, printing the CR_REFERENCE field. You should be able to troubleshoot your filtering there.

    You can also check otaAttachment.Fields to see that CR_REFERENCE is in fact filterable.

  • I have tried removing the filtering part but in all cases the collection is empty. I have eventually figured out that the filter part is not the issue (or not for now), but the issue comes from the following:

    Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
    Set otaAttachmentFactory = otaSysTreeNode.Attachments

    At the moment, the TDFolderPath is set to one of the folders from the test plan for testing purposes. That folder contains a few tests, which contain attachments.

    I need to figure a way to run through all the child nodes of that node, as the child nodes would represent the actual tests in this scenario. 

  • The Attachments property in your example will  only get you the attachments to the specified folder.

    If you want to access the attachments to the tests in that folder, you need to go via its TestFactory.

    And remember that attachments could also belong to individual Design Steps, so you will need the DesignStepFactory for each test as well.