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:

Leave a comment:

preeti - August 10, 2012

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.


    Joe Colantonio - August 10, 2012

    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?

sandhya - September 13, 2012

Can we upload fields value through excel to test lab using OTA…?

Jatinder Singh - October 23, 2012

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.

    Joe Colantonio - November 16, 2012

    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,” “,””)

Giridhar - November 12, 2012


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.


Rita - November 29, 2012


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 ??


Lee Godfrey - December 5, 2012

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.

Kweeks - January 5, 2013

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 !

    Kweeks - January 7, 2013

    Found the answer. First of all, need to check that the field has a value (i.e. IsEmpty = False); then, need to refer to the field as: bug.Field(“BG_TARGET_REL”).Name.

Maharshi Gurrala - January 18, 2013

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

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

    Joe Colantonio - January 25, 2013

    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

Jegan - February 25, 2013

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

Jimmy - March 13, 2013

Hi Joe,

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


    Joe Colantonio - March 14, 2013

    Jimmy » HI Jimmy – I do have a post planned on the ALM REST API – I just have not done it yet. I will try to get it posted soon.

Raj - April 3, 2013

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.


Sreekanth - September 27, 2013

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.

Nitin - October 1, 2013

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.


Ramkumar - November 7, 2013

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.

Sri - December 9, 2013

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

Ramkumar Ponnath - January 7, 2014

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 ?

Sandeep - February 5, 2014

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 - April 14, 2014

    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

      Paul Clarke - April 14, 2014

      Sorry, I missed the bug table part. My response wasn’t quite what you are looking for.

Ram - February 21, 2014

How to use OTA to link a requirement to a defect

Prasanna - February 27, 2014

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 @

Ravi - March 14, 2014


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

Can some one help me with the code.


Nitin - April 14, 2014

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.


Nutan - June 5, 2014

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

Huangfu - November 3, 2014

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?

Amrita Kaur - June 18, 2015

I am using HP ALM QC tool to manage my bugs. Actually we have a dot net Application and we are inserting the bugs by using API.

We are able to post the comments from the application to QC tool through API using

But I want to pass the history to store something in History on QC tool. I don’t have a way for this.

We want to pass the values changed in History field.

Please help me out.


Arav - October 5, 2015


Is there a way in qc workflow to filter detected in cycle ( defect form) by date/other way so that it only displays cycles based on current release ?

Please help me


Click here to add a comment

Leave a comment: