Highlighted
brigna Trusted Contributor.
Trusted Contributor.
179 views

Downloading defects attachments using OTA API

Jump to solution

Hi

I'm needing to download the attachments of defects that meet a specific criteria from the repository to another file system using OTA API (or any other way anybody knows).  I'm using QC 11.0.

So I need to move the attachments of defects with the following filter

BG_ATTACHMENT = "Y" and BG_STATUS = "Closed" and BG_CLOSING DATE <= "01/08/2014"

from the repository to C:\Temp\OTABugs  but with some way to identify them as belonging to that defect (folder\filename)

I've tried various bits of code from this board and online, but can't get anything to work.  I'm not very good at coding, so mine is a bit of a mess now.

 

Sub attachments()

Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://********:8080/qcbin"
tdc.Login "******", "*******"
If Err.Number <> 0 Then
MsgBox "Error occurred with description: " & Err.Description
Exit Sub
End If

tdc.Connect "DEFAULT", "QCADMIN_DeliveryProject_Issues"

If tdc.Connected = True Then
MsgBox "User Authenticated successfully. !!"
Else
MsgBox "User Authentication is Failed. Please check you access to HP ALM. !!!"
End If

DownloadDefectsAttachments ("C:\temp\OTABugs")

End Sub

Public Function DownloadDefectsAttachments(AttachmentDownloadPath As String)

Dim OBugFactory
Dim OTDFilter As Filter
Dim OBug 
Dim OBugList 
Dim OAttachmentFactory
Dim OExtendedStorage


Set OBugFactory = tdc.BugFactory
Set OTDFilter = OBugFactory.Filter
Set OBugList = OBugFactory.List
Set OAttachmentFactory = tdc.AttachmentFactory
Set OExtendedStorage = tdc.ExtendedStorage
Set OBug = tdc.Bug
Set OAttachment = tdc.Attachment

Console.WriteLine ("Downloading attachments for the Defects : " + AttachmentDownloadPath)
MsgBox ("Downloading attachments for the Defects : " + AttachmentDownloadPath)


OTDFilter ["BG_ATTACHMENT"] = "Y", ["BG_STATUS"] = "Closed", [BG_CLOSING_DATE] <= "01/08/2014"
OBugList = OBugFactory.NewList(OTDFilter.Text)

For Each OBug In OBugList
Directory.CreateDirectory (AttachmentDownloadPath + "\\" + OBug.ID.ToString())
Console.WriteLine ("Downloading attachments for the Defect : " + OBug.Summary.ToString())
OAttachmentFactory = OBug.attachments

'Download defect attachments
For Each OAttachment In OAttachmentFactory.NewList("")
OExtendedStorage = OAttachment.AttachmentStorage
OExtendedStorage.ClientPath = AttachmentDownloadPath + "\\" + OBug.ID.ToString()
OAttachment.Load OAttachment.Name, True
Next
Next

End Function

 

Any help would be greatly appreciated

0 Likes
1 Solution

Accepted Solutions
brigna Trusted Contributor.
Trusted Contributor.

Re: Downloading defects attachments using OTA API

Jump to solution

Thanks for your help, Jan & Vladimir.

I managed to get the code working, although I couldn't get it download the attachments to a designated folder, only the default one, but it's no big issue.

e.g. C:\Users\myuser\AppData\Local\Temp\TD_80\TDAPIC~1\ba2fcdae\Attach\BUG\nnnnnn

 
Sub Attachments()
 
Set tdc = CreateObject("TDApiOle80.TDConnection")
    tdc.InitConnectionEx "http://*******:8080/qcbin"
    
    '*************Enter ALM Login Details -  "Usename", "Password"******************
    tdc.Login "*******", "********"
    
        
    '************Enter ALM Project Details - "DEFAULT", "Project Name"****************
    tdc.Connect "DEFAULT", "*********"
 
    
    Dim BugFact As BugFactory
    Dim bugObj As Bug
    Dim attachFact As AttachmentFactory
    Dim attachObj As Attachment
    Dim attachList As List
    Dim bugL As List
    Dim LoadPath As String
    Dim BgFilter As TDFilter
            
 
    'tdc is the global TDConnection object.
    Set BugFact = tdc.BugFactory
    Set BgFilter = BugFact.Filter
    
    'Set the Filter
    BgFilter.Filter("BG_USER_28") = "Not FLS And  Not TSA And  Not Unassigned"
    BgFilter.Filter("BG_CLOSING_DATE") = "Not < 01/08/2019"
    BgFilter.Filter("BG_DETECTION_DATE") = ">= 01/09/2014"
    BgFilter.Filter("BG_USER_30") = "Not Y"
    BgFilter.Filter("BG_USER_10") = "Not N"
    BgFilter.Filter("BG_STATUS") = "Not Migrated"
    BgFilter.Filter("BG_PROJECT") = "Not ""Financial Reconciliation"""
    BgFilter.Filter("BG_ATTACHMENT") = "Y"
 
    
    Set bugL = BgFilter.NewList
    For Each bugObj In bugL
        ' Get an attachment.
        Set attachFact = bugObj.Attachments
        Set attachList = attachFact.NewList("")
        Set attachObj = attachList.Item(1)
        For Each attachObj In attachList
            'Use Attachment.Load to download the attachment.
            attachObj.Load True, LoadPath
            ' Output the actual download location.
            Debug.Print LoadPath
            'e.g. C:\Users\myuser\AppData\Local\Temp\TD_80\TDAPIC~1\ba2fcdae\Attach\BUG\nnnnnn
'See Immediate Window for path when running
        Next attachObj
    Next bugObj
    
    tdc.Logout
    Set tdc = Nothing
End Sub

 

This downloads theAttachments ScreenCapture.JPG attachments in this format

0 Likes
5 Replies
Knowledge Partner Knowledge Partner
Knowledge Partner

Re: Downloading defects attachments using OTA API

Jump to solution

The filter creation looks very strange to me. Here is how I would do it:

Set bugFilter = OBugFactory.Filter
bugFilter.Filter("BG_ATTACHMENT") = "Y"
bugFilter.Filter("BG_STATUS") = "Closed"
bugFilter.Filter("BG_CLOSING_DATE") = "<= 01/08/2014"
OBugList = bugFilter.NewList
Jan Czajkowski

[Please do not contact me off line for receiving support. Use the forum!]
0 Likes
brigna Trusted Contributor.
Trusted Contributor.

Re: Downloading defects attachments using OTA API

Jump to solution

Thanks Jan

Yes, that looks better, I wasn't sure how to format the filter for multiple options.  I've been copying bits and pieces from all over the place, that why the code looks so bad.

 

It's not even getting as far as the filter, it's falling over at the first Set command looking for an object.

Set OBugFactory = tdc.BugFactory

0 Likes
brigna Trusted Contributor.
Trusted Contributor.

Re: Downloading defects attachments using OTA API

Jump to solution

Public Function DownloadDefectsAttachments(AttachmentDownloadPath As String)

Dim OBugFactory
Dim OBugFilter
Dim OBug
Dim OBugList
Dim OAttachmentFactory
Dim OExtendedStorage

Set OBugFactory = tdc.BugFactory
Set OBugList = OBugFactory.List
Set OAttachmentFactory = tdc.AttachmentFactory
Set OExtendedStorage = tdc.ExtendedStorage
Set OBug = tdc.Bug
Set OAttachment = tdc.Attachment

Console.WriteLine ("Downloading attachments for the Defects : " + AttachmentDownloadPath)
MsgBox ("Downloading attachments for the Defects : " + AttachmentDownloadPath)

Set OBugFilter = OBugFactory.Filter
OBugFilter.Filter("BG_ATTACHMENT") = "Y"
OBugFilter.Filter("BG_STATUS") = "Closed"
OBugFilter.Filter("BG_CLOSING_DATE") = "<= 01/08/2014"
OBugList = OBugFilter.NewList

 

OK, so I've put Jan's code in for the filter, but it falls over at the first set command with an error 'Object Required'.  Do the Dim and Set sections look right, am I missing something or is it completely wrong?

0 Likes
Knowledge Partner
Knowledge Partner

Re: Downloading defects attachments using OTA API

Jump to solution

If you run the OTA API from VBScript then I use for getting the "TDC" object this code:

----------------------
set tdc=createobject("TDApiOle80.TDConnection.1")
tdc.initconnectionEx "https:///qcbin"
tdc.login "username","password"
tdc.connect "DOMAINNAME","ProjectName"
PrintStr "Start datetime: " & tdc.ServerTime
tdc.disconnect
tdc.logout
-----------------

See if you see the right server time.

If yes you can follow code with:

set OBugFact = tdc.BugFactory
...

0 Likes
brigna Trusted Contributor.
Trusted Contributor.

Re: Downloading defects attachments using OTA API

Jump to solution

Thanks for your help, Jan & Vladimir.

I managed to get the code working, although I couldn't get it download the attachments to a designated folder, only the default one, but it's no big issue.

e.g. C:\Users\myuser\AppData\Local\Temp\TD_80\TDAPIC~1\ba2fcdae\Attach\BUG\nnnnnn

 
Sub Attachments()
 
Set tdc = CreateObject("TDApiOle80.TDConnection")
    tdc.InitConnectionEx "http://*******:8080/qcbin"
    
    '*************Enter ALM Login Details -  "Usename", "Password"******************
    tdc.Login "*******", "********"
    
        
    '************Enter ALM Project Details - "DEFAULT", "Project Name"****************
    tdc.Connect "DEFAULT", "*********"
 
    
    Dim BugFact As BugFactory
    Dim bugObj As Bug
    Dim attachFact As AttachmentFactory
    Dim attachObj As Attachment
    Dim attachList As List
    Dim bugL As List
    Dim LoadPath As String
    Dim BgFilter As TDFilter
            
 
    'tdc is the global TDConnection object.
    Set BugFact = tdc.BugFactory
    Set BgFilter = BugFact.Filter
    
    'Set the Filter
    BgFilter.Filter("BG_USER_28") = "Not FLS And  Not TSA And  Not Unassigned"
    BgFilter.Filter("BG_CLOSING_DATE") = "Not < 01/08/2019"
    BgFilter.Filter("BG_DETECTION_DATE") = ">= 01/09/2014"
    BgFilter.Filter("BG_USER_30") = "Not Y"
    BgFilter.Filter("BG_USER_10") = "Not N"
    BgFilter.Filter("BG_STATUS") = "Not Migrated"
    BgFilter.Filter("BG_PROJECT") = "Not ""Financial Reconciliation"""
    BgFilter.Filter("BG_ATTACHMENT") = "Y"
 
    
    Set bugL = BgFilter.NewList
    For Each bugObj In bugL
        ' Get an attachment.
        Set attachFact = bugObj.Attachments
        Set attachList = attachFact.NewList("")
        Set attachObj = attachList.Item(1)
        For Each attachObj In attachList
            'Use Attachment.Load to download the attachment.
            attachObj.Load True, LoadPath
            ' Output the actual download location.
            Debug.Print LoadPath
            'e.g. C:\Users\myuser\AppData\Local\Temp\TD_80\TDAPIC~1\ba2fcdae\Attach\BUG\nnnnnn
'See Immediate Window for path when running
        Next attachObj
    Next bugObj
    
    tdc.Logout
    Set tdc = Nothing
End Sub

 

This downloads theAttachments ScreenCapture.JPG attachments in this format

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.