Create a defect

Public Function NewBug(BugSummary As String, _
     Optional bugDescription = "description of new bug", _
     Optional DetectedByUserName As String, _
     Optional BugSeverity = "2-Medium", _
     Optional DetectedDate) _
     As Bug
' Create a defect


    Dim BugF As BugFactory
    Dim TheNewBug As Bug
    
    On Error GoTo FUNC_ERR

    Set BugF = tdc.BugFactory
    Set TheNewBug = BugF.AddItem(Null)
    
    If IsMissing(DetectedDate) Then DetectedDate = Date$
    If IsMissing(DetectedByUserName) Then
        DetectedByUserName = tdc.UserName
    Else
        If Len(DetectedByUserName) = 0 Then DetectedByUserName = "alex_alm"
    End If
    
    'Required fields. Get the list of required fields for your project with URL:
    'http://<host>:<port>/qcbin/rest/domains/<DOMAIN NAME>/projects/<PROJECT NAME>/customization/entities/defect/fields?login-form-required&required=true
    'For more information, see the ALM REST API documentation (help->documentation library)
    With TheNewBug
        .Summary = BugSummary
        .DetectedBy = DetectedByUserName
        .Field("BG_DETECTION_DATE") = DetectedDate
        .Field("BG_SEVERITY") = BugSeverity
    End With
    
    'Examples of other fields you can set:
    With TheNewBug
        .AutoPost = False
        .AssignedTo = "alex_alm"
        .Priority = "1-Low"
        .Status = "New"
        .Field("BG_DESCRIPTION") = bugDescription
        .Field("BG_REPRODUCIBLE") = "Y"
        .Field("BG_PRIORITY") = "2-Medium"
        .Field("BG_RESPONSIBLE") = "alex_alm"
        .Field("BG_STATUS") = "New"
        .Field("BG_USER_01") = "123"
    End With
    
    TheNewBug.Post
    
   Set NewBug = TheNewBug
Exit Function
FUNC_ERR:
    Set NewBug = Nothing
End Function