The below method takes a technical field name of an HP ALM BUG field and a corresponding filter condition like a bug id and returns a bug uniquely identified by handed filter condition.
Source Code
' @Author - Alexander Bolte
' @ChangeDate - 2015-01-07
' @Description - Returns an object of type Bug, if the provided filter
' returns only one defect.
' @Param idField - a String providing the technical field name of the field
' a filter should be set up for.
' @Param id - an unique identifier for one defect in current ALM Defect module.
' @Returns an object of type Bug, if one unique bug could be identified.
' Else Nothing is returned. In case of any error Nothing is returned.
Function getBugByField(idField, id)
Dim BugF ' As BugFactory
Dim bg ' As Bug
Dim BugList ' As IList
On Error Resume Next
' Preset bg to Nothing.
Set bg = Nothing
' Setting the bug factory.
Set BugF = TDConnection.BugFactory
' Creating the filter to search for rule id.
Set fltr = BugF.Filter
fltr.Filter(idField) = checkCondition(id)
Set BugList = fltr.NewList()
If BugList.Count = 1 Then
Set bg = BugList.Item(1)
End If
If Err.Number <> 0 Then
Err.Clear
Set bg = Nothing
End If
Set bugList = Nothing
Set bugF = Nothing
Set getBugByField = bg
End Function