ALM/QC – How to Update a Defect using OTA

How to update an ALM defect using Open Test Architecture API (OTA)

The question of the week comes one of my co-workers who asked:

I’m looking to use the ALM11 API to update a field within an existing Defect. I know you are using the API to create Defects. Have you (or know how to) update a field on an existing Defect?”

OTA Code to Update a Defect in ALM/QC

The following example updates a defect that has the ID of 17 and changes the status field to Fixed. The code is pretty straight forward and uses the OTA’s BugFactory object to accomplish our goal. Creating an instance of the BugFactory object allows us to access all the services needed to manage defect records.

set tdc = createobject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://yourURL/qcbin"
tdc.Login "yourName","yourPassword"
tdc.Connect "yourDomain","yourProject"
DefectID = 17
Set BugFactory = tdc.BugFactory
Set BugFilter = BugFactory.Filter
BugFilter.Filter("BG_BUG_ID") = DefectID
Set BugList = BugFilter.NewList
Set myBug = BugList.Item(1)
'Just need to know the qc field name value
myBug.Field("BG_STATUS") = "Fixed"
Set BugFilter = Nothing
Set myBug = Nothing
Set BugFactory = Nothing
Set BugFilter = Nothing

How to run the code

To run the defect code you can either place it in QTP and run as a script or place the code in a text file and save as a .VBS vbscript file.

How to get the QC/ALM field name

Of course you will be using the field names found in your ALM project. If you don’t know what the actual field names are, you can easily find them by going into QC’s Tools>Customize. In the Project Customization section and go into the “Project Entities” section. Under the Project Entities Tree view click expand Defect and click on your System Folder or User Fields. Clicking on a field will reveal the field name that you will need to use:


  1. preeti says

    how to append value in the “Comments” field of the bug ? I want the existing comments to be retained and just want to add a line more before changing the status of bug.
    The above mentioned code overwrites my entire “Comments” field with the single line that i’m trying to add.


    • says

      preeti » Hello- Before doing the post you can get the existing value and append your new text to it then post the new comment value. For example:

      nowComment = myBug.Field(“BG_DEV_COMMENTS”)
      newComment = nowComment & ” this is the text I’d like to append”
      myBug.Field(“BG_DEV_COMMENTS”) = newComment

      Make sense?

  2. Jatinder Singh says

    I am trying to get a list of defects and im using the release field as filter for the same. I’m facing 2 problems:
    1) My release name say example month date contains space in between so its giving an error for space also
    2) I tried with Field BG_TARGET_REL with .Name and .Value also but its erroring out
    Please let me know how to go about this.

    • says

      Jatinder Singh » Can you send me the code that is causing you this issue? For adding the BG_TARGET_REL did you try bug.Field(“BG_TARGET_REL”) = “yourRelease”? To remove unwanted spaces in a variable you can use the r = instr(myrelDate,” “,””)

  3. Giridhar says


    I have a field in test set which is a list. I want to add more items to the list. how do I achieve it, please let me know. I am using perl script to connect to QC.


  4. Rita says


    I am trying to submit a defect through QTP. I have provided all the values needed for posting the Defect.
    Bug.Post logs the defect in QC. But the automatic mail notification that should happen when a defect is assigned to someone – doesn’t happen. The mail get triggered when I manually submit a defect.
    Any thoughts on what I am missing ??


  5. Lee Godfrey says

    Hi great article… really useful.

    Just wondering… Is there anyway to evaluate whether or not BugFilter.Filter has results before continuing. I am using an excel report, looping through it to update bugs in QC. I look for a particular project number in the excel file to match a field in QC. Only if there is a match I want it to update the field.

  6. Kweeks says

    I’m also having a problem accessing the bug field, BG_TARGET_REL. I keep getting “invalid property assignment”, is it because the field is not a string?
    Code (with and without quotes “1029”) looks like:
    and Bug.Field(“BG_TARGET_REL”) = 1029
    And with this:
    Sheet.Cells(Row, 9).Value = Bug.Field(“BG_TARGET_REL”)
    I get an unknown error.
    I’ve checked the OTA client DLL.
    Thanks !

  7. Maharshi Gurrala says

    I want to get the defect COUNT from QC using a VB code with the following Filters combination:

    /*1.BG_DETECTED_IN_REL=”December 2012 ”
    3.BG_DETECTED_BY=”aa39645″ */

    The following is the code that I have used.I tried to output the Count of defects satisfyingt the above filter conditions,but I am getting AUTOMATION ERROR when I ran the VB script.Please help

    ‘MY CODE
    Sub DefectHistoryReport()
    ‘Give the ALM URL
    strQCURL = “http://qtomavmpc025:8080/qcbin/”
    strQCDomain = “DEFAULT”

    ‘Select the Project for which we need to pull the data
    strQCProject = “My QC Project”

    ‘Enter the ALM User name and Password
    User = InputBox(“Enter QC username”, “******”)
    pass = InputBox(“Enter QC password”, “******”)

    Dim com ‘As TDAPIOLELib.Command
    Dim bugfac ‘As TDAPIOLELib.TestFactory
    Dim buglist ‘As TDAPIOLELib.List
    Dim bugfilter ‘As TDAPIOLELib.TDFilter

    Dim hst ‘As TDAPIOLELib.History
    Dim hstRec ‘As TDAPIOLELib.HistoryRecord
    Dim hstList ‘As TDAPIOLELib.List

    Set tdc = CreateObject(“TDApiOle80.TDConnection”)
    tdc.InitConnectionEx (strQCURL)
    tdc.Login User, pass
    tdc.Connect strQCDomain, strQCProject

    Dim Bug_Ct: Bug_Ct = 0
    Set oBugFactory = tdc.BugFactory
    Set oBugFilter1 = oBugFactory.Filter
    oBugFilter1.Filter(“BG_DETECTED_IN_REL”) = “December 2012 ” ‘Name of the Release
    oBugFilter1.Filter(“BG_STATUS”) = “Closed” ‘Defect status for which count is calculated
    oBugFilter1.Filter(“BG_DETECTED_BY”) = “****” ‘QC Username of the testers for whom the count is calculated
    Bug_Ct = Bug_Ct + oBugFactory.NewList(oBugFilter1.Text).Count
    MsgBox Bug_Ct
    Set oBugFilter1 = Nothing

    End Sub

    • says

      Maharshi Gurrala » What line of code is it failing on? What happens if you try to simplify it (using just one filter on status) to see if it works. The following vbscript that worked for me:

      set tdc = createobject(“TDApiOle80.TDConnection”)
      tdc.InitConnectionEx “http://yourURL/qcbin”
      tdc.Login “yourName”,”yourPassword”
      tdc.Connect “yourDomain”,”yourProject”
      Set BugFactory = tdc.BugFactory
      Set BugFilter = BugFactory.Filter
      BugFilter.Filter(“BG_STATUS”) = “Closed”
      BugList = BugFilter.NewList.Count
      msgbox BugList

  8. Jegan says

    Hi Joe,
    While updating comments in QC , is it possible to get the username date format as reflecting in HP QC using vbs.

  9. Jimmy says

    Hi Joe,

    Just wondering, since ALM 11 provides REST API, have you tried that method? Can you share us your experience?


  10. Raj says

    I am new to QTP and I am using QTP 11.0 for functional testing.

    I have a scenario where I have QTP is installed (and Scripts) are on one machine (Say Machine1) and AUT is in another machine (Say Machine 2)
    and both Machine 1 & Machine 2 are in same network.

    I want to run my qtp scripts such a way that Script must run on Machine 1 but Action must be performed on Machine 2.
    I am using Win XP in both machines.
    Please let me know the procedure.


  11. Sreekanth says

    Hi, i am trying to extract the values of Detected in Cycle field from QC defects section.

    well i treid below code to extract value of Defect status field:

    Set cust = QCConnection.customization
    Set custlists = cust.Lists
    Set custlist = cutslists.List

    Set custlist = custlists.List(“Bug Status”) ‘it is listing complete bug status values not specific ‘to the project
    Set listrootnode = custlist.RootNode
    Set listchildren = listrootnode.Children
    For Each listname In listchildren
    MsgBox (listname.Name) ‘Assigned, deferred, cancel…… all are displayed

    But here i am not able to replace “Bug Status” for “Detected in Cycle”…So please help me by letting me know what is the custom list name for Detected in cycle field. Or please provide any solution if you got any.

  12. Nitin says

    Hi Joe

    The actual fix time field in defect is not getting updated automatically. We need to click on cell to update it. Please let me know what can be done to make function properly.


  13. Ramkumar says

    This is excellent, Able to update the defect fields. Is there a way to get the inputs for defect ID and status from a excel sheet.

  14. Sri says

    I want to get Planned prod Date and Detected in Env(BG_DETECTED_IN_RCYC) from QC 11.0
    Could you please help me.
    Thanks in advance

  15. Ramkumar Ponnath says

    Hi, When i try to assign the value to the specific field in the release using the below code
    val.Field(“Rel_REQ_Count”)=5, i am getting the below error
    SyntaxError: can’t assign to function call

    Can anyone help to resolve this issue ?

    is it possible to assign the value to the functional call ?

  16. Sandeep says

    How do i know the columns in the bug table?
    I am able to find

    But I need other column names so that I can copy data from my excel and post a bug in QC using tdapiolelib.dll

    • Paul Clarke says

      Here is the VBSCript I use for the information that is important to me….

      Option Explicit
      Dim qcServer, project, tdc
      dim custfield, custfields, cust, msg, listname, bglist
      Dim fileName, fso, f

      project = “your project name”

      fileName = “C:\Temp\” & project & “.csv”
      Set fso = CreateObject (“Scripting.FileSystemObject”)
      Set f = fso.CreateTextFile (fileName, True)
      qcServer = “http://your server/qcbin”

      Set tdc = CreateObject(“tdapiole80.tdconnection”)
      tdc.InitConnectionEx qcServer
      tdc.Login “your user name”, “your user passwd”
      tdc.Connect “your domain name” , project
      Set cust = tdc.Customization
      Set custfields = cust.Fields

      ‘Column headers for the csv file
      msg = “Field Name,Field Label,Type,Mask,List Name,Keep History,Required,” & _
      “Verify,Multi Value,Searchable” & chr(13)

      For Each custfield In custfields.Fields(“Bug”)
      listname = “”

      Set bglist = custfield.List
      if Not bglist is Nothing then
      listname =
      End If

      If CustField.IsActive then
      msg = custfield.ColumnName & “,” & _
      custfield.UserLabel & “,” & _
      custfield.UserColumnType & “,” & _
      custfield.editMask & “,” & _
      listname & “,” & _
      custfield.IsHistory & “,” & _
      custfield.IsRequired & “,” & _
      custfield.IsVerify & “,” & _
      custfield.IsMultiValue & “,” & _
      End If

      Msgbox “Done!”

      f.Close ()

      Set f = Nothing
      Set fso = Nothing
      Set tdc = Nothing
      Set cust = Nothing
      Set custfields = nothing

  17. Prasanna says

    Hi I am trying to upload defects to QC fro Excel inputs. I have a field ‘BG_DETECTED_IN_RCYC’ which is mandatory in QC. I am unable to pass the value for that field from Excel. I found that this field is actually taking the value from release folder based on the ID. similarly there are other requirements fields which is not actually a field in Bug table but a reference from the requirement table.
    now my question is how to assign the value to this field?
    code goes here:
    Set BugF = tdc.BugFactory
    Set Bug1 = BugF.AddItem(Null)
    ‘for all the mandatory fields
    Bug1.field(“BG_DETECTED_IN_RCYC”) = Sheets(“Defects”).Cells(6, 3).Value – its picking blank value.

    i tried getting the value and i am unable to assign it to this field. can anyone help me out with exact code that i need to use?

    you can mail me @

  18. Ravi says


    I want to update the Test: Comments column under executiong grid QC test lab.

    Can some one help me with the code.


  19. Nitin says

    This is awesome.

    I am using the code suggested by you as below to update the defect comments section by adding line below the existing comments .

    ‘nowcomment = myBug.Field(“BG_DEV_COMMENTS”)
    ‘newComment = nowComment & ” this is the text I’d like to append”
    ‘myBug.Field(“BG_DEV_COMMENTS”) = newComment

    But this code is not working as nowcomment = myBug.Field(“BG_DEV_COMMENTS”) has no value when running in debug mode.Its not showing the existing values in comments sections.

    Can you please help its really very imp for me.


  20. Nutan says

    Can any one tell what is the field name for Assigned to in QTP
    if i give BG_ASSIGNED_TO its through error message. Please help

  21. says

    Please help me, now I cannot reference the OTAClient.dll with VB or
    C# in Visual Studio 2010. And I cannot run the script with VBS as below. What can I do next?

Leave a Reply

Your email address will not be published. Required fields are marked *