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: