ALM/QC – How to Update a Defect using OTA

by Joe Colantonio on August 9, 2012

Post image for 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"
myBug.Post
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:


{ 16 comments… read them below or add one }

preeti August 10, 2012 at 11:24 am

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.

Thanks,

Reply

Joe Colantonio August 10, 2012 at 12:44 pm

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?

Reply

sandhya September 13, 2012 at 4:43 pm

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

Reply

Joe Colantonio September 15, 2012 at 12:04 am

sandhya » What values in the test lab are you trying to update?

Reply

Jatinder Singh October 23, 2012 at 2:18 pm

Hi,
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.

Reply

Joe Colantonio November 16, 2012 at 4:22 pm

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

Reply

Giridhar November 12, 2012 at 6:43 am

Hi,

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.

Thanks
Giridhar

Reply

Joe Colantonio November 12, 2012 at 7:06 pm

Giridhar » Hi Giridhar – you should be able to do this by using the OTA Customization option. For an example check out QC List customization–Adding list items using OTA API

Reply

Kweeks January 5, 2013 at 1:04 am

Hi.
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 !
K.

Reply

Kweeks January 7, 2013 at 10:27 pm

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.

Reply

Joe Colantonio January 8, 2013 at 1:15 pm

Kweeks » Cool – thanks for the update!!

Reply

Maharshi Gurrala January 18, 2013 at 7:50 am

Hi,
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 ”
2.BG_STATUS=”Closed”
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

tdc.DisconnectProject
tdc.ReleaseConnection
End Sub

Reply

Joe Colantonio January 25, 2013 at 3:34 pm

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

Reply

Jimmy March 13, 2013 at 5:12 am

Hi Joe,

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

Regards,
Jimmy.

Reply

Joe Colantonio March 14, 2013 at 1:42 pm

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.

Reply

Raj April 3, 2013 at 6:26 am

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.

Regards,
RAJ

Reply

Leave a Comment

Previous post:

Next post: