Downloading Attachments from ALM/QC Requirements Module

Introduction

HP ALM, is a tool developed by HP, for managing the quality of a software. There are several modules available in ALM, and most of them (like defects, tests etc.) will allow uploading the attachments to it. At times either for analysis or for migration purpose we will need to download the bulk attachments from QC. In this post, we will see how to download attachments from different modules from QC. Code is written in C# and can be easily converted to any other language.

Downloading Attachments

For downloading attachments from requirements module, we will first have to create the ALM Connection Object which is described here.

After you have successfully created the Object of TDConnection, then Copy the following function into your code execute the scripts, all of the attachments will be downloaded in the desired folder.


public static Boolean DownloadRequirementsAttachments(String AttachmentDownloadPath)
        {
            TDAPIOLELib.ReqFactory OReqFactory = OQConnection.ReqFactory as TDAPIOLELib.ReqFactory;
            TDAPIOLELib.TDFilter OTDFilter = OReqFactory.Filter as TDAPIOLELib.TDFilter;
            TDAPIOLELib.List OReqList;

            TDAPIOLELib.AttachmentFactory OAttachmentFactory;
            TDAPIOLELib.ExtendedStorage OExtendedStorage;

            Console.WriteLine("Downloading attachments for the Requirements : " + AttachmentDownloadPath);

            try
            {
                //Check if the directory exists
                if ((System.IO.Directory.Exists(AttachmentDownloadPath)) == false)
                {
                    Debug.WriteLine("Cannot find the attachments download folder");
                    return false;
                }
                OTDFilter["RQ_ATTACHMENT"] = "Y";
                OReqList = OReqFactory.NewList(OTDFilter.Text);
                foreach (TDAPIOLELib.Req OReq in OReqList)
                {
                    if (OReq.HasAttachment)
                    {
                        Directory.CreateDirectory(AttachmentDownloadPath + "\\" + OReq.ID.ToString());
                        Console.WriteLine("Downloading attachments for the Requirement : " + OReq.Name.ToString());
                        OAttachmentFactory = OReq.Attachments;
                        //Download the Requirement attachments
                        foreach (TDAPIOLELib.Attachment OAttachment in OAttachmentFactory.NewList(""))
                        {
                            OExtendedStorage = OAttachment.AttachmentStorage;
                            OExtendedStorage.ClientPath = AttachmentDownloadPath + "\\" + OReq.ID.ToString();
                            OAttachment.Load(true, OAttachment.Name);
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error occurred while downloading the attachments : " + ex.Message.ToString());
                return false;
            }
        }

 

How it works

For downloading the attachments from requirements, we will use the following objects

  • ReqFactory : Req Factory object is the requirement manager class of OTA API. This can be used for creating and managing the requirements.
  • Req : Req is the actual requirement object which will represent a single requirement at any given point of time.
  • TDFilter : TDFiler Object if the Filter type object of the OTA API and can be used for filtering data from any modules.
  • AttachmentFactory : Attachment Factory Object is the Attachment manager class of OTA API. This will be used for managing the attachments.
  • ExtendedStorage : it is the storage handler object of the OTA API and will be used for downloading the attachment to the desired folder.

For downloading the requirement attachments, first we have to filter the requirements with attachments; otherwise, it might take a lot of time for the bigger projects to navigate through all of the requirements.

ALM will store value ‘Y’ in the field “RQ_ATTACHMENT” and we will use this field to filter the requirements with attachments.


OTDFilter["RQ_ATTACHMENT"] = "Y";

OReqList = OReqFactory.NewList(OTDFilter.Text);

After the execution of the above statements, we will get the list of Requirement objects with attachments in OReqList object.

Now, for each of the listed Requirements, we will get the attachments object


OAttachmentFactory = OReq.Attachments;

And then we will download the attachments using the extended storage objects.

Let me know, if you need any help, I will try to provide the solutions.

Thanks

Advertisements

8 responses to “Downloading Attachments from ALM/QC Requirements Module

  1. Pingback: DOWNLOADING ATTACHMENTS FROM ALM/QC, Tests and Design Steps module | Automation Insights·

    • Hi,

      You can use one of the following

      1) Database field : REQ.Field(“RQ_REQ_RICH_CONTENT”)

      2) You can try using the LoadRichContent Function

      http://alm-help.saas.hpe.com/en/12.50/api_refs/ota/topic8492.html

      3) you can try using the below code, I found it somewhere on the internet

      It uses GenerateRichContentHTMLDocumentMethod

      http://alm-help.saas.hpe.com/en/12.20/api_refs/ota/topic8345.html

      ‘tdc = CreateObject(“TDAPIOLE80.TDConnection.1”)
      Dim qcServer As String
      Dim tdc As New TDAPIOLELib.TDConnection
      Dim qcUser As String
      Dim qcPassword As String
      Dim qcDomain As String
      Dim qcProject As String

      qcServer = “http://:/qcbin”

      tdc.InitConnectionEx(qcServer)

      qcUser = “”
      qcPassword = “”
      qcDomain = “”
      qcProject = “”

      tdc.Login(qcUser, qcPassword)

      tdc.Connect(qcDomain, qcProject)
      MsgBox(“user admin is logged”)

      Dim reqfct As TDAPIOLELib.ReqFactory
      Dim myReq As TDAPIOLELib.Req
      Dim RichContent As TDAPIOLELib.ISupportRichContent
      Dim SourceFile

      reqfct = tdc.ReqFactory
      myReq = reqfct.Item(1)
      RichContent = myReq

      SourceFile = RichContent.GenerateRichContentHTMLDocument(“REQ”, “1”)
      MsgBox(“source file” + SourceFile.ToString())

      Like

  2. Hi need some help I need to download the attachment from test lab from executed test cases
    so I am not sure how to give the path for each test cases

    any help on this

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s