Back to Blog

ALM Workflow: Always Trigger Bug_New when “New Defect” is Clicked

One “feature” in HP’s Application Lifecycle  Management (ALM) and Quality Center relating to the Defects module is the ability to add multiple defects without ever closing the “New Defect” window, and to resume populating a new defect after the “Close” button is clicked. When the user clicks the “Close” button and then “New Defect”, the field values are cached. This can be a great time saver; however, it is not without its unintended consequences. This means that the Bug_New event is not triggered when clicking the “New Defect” button, which can have adverse effects.

Imagine this scenario:

  1. From within the Defects module, click the  “New Defect” button.
  2. Begin populating a new defect record.
  3. You notice that something odd has happened – a required and read only field that should automatically be populated is empty. You cannot insert a new defect. You then click the “Close” button assuming you will have a clean defect window when you click “New Defect” again. Note:  You also reported this bug to your workflow guru (or attempted to debug this yourself), but he/she cannot determine the cause (or reproduce the issue) as it seems sporadic.
  4. You now click the “New Defect” button to start a new defect. The defect record is in the same state as when the “Close” button was clicked. You are now stuck – you cannot submit a defect record, unless you log out or enter the Customization area (from within Tools), because the field values are cached at this point and the state of the required field is still read-only.

Adding debug code (MsgBox) in Bug_New illustrates that the event is not triggered after the “Close” button in the “New Defect” window is clicked (and then the “New Defect” button is clicked). Bug_New is not triggered again until a defect record is saved.

To work around this “feature” we have to add code to the DialogBox subroutine that executes code every time the “New Defect” button is clicked. Essentially, Bug_New will execute every time you expect it to, bypassing the built-in “feature.” In Bug_New and DialogBox you will need to call an initialization function (CUSTOM_BUG_Init) that clears all of the fields on the record and sets the location, visibility and read only properties of fields. CUSTOM_BUG_Init must still be called from within Bug_New because the DialogBox event is not triggered after clicking the “Submit” button. A global variable will need to be used that tracks when the CUSTOM_BUG_Init function has been executed (so that it is not executed twice when clicking the “New Defect” button). Below is that code in action, tested in ALM (Quality Center) 11 (Patch level 0 through SP3).

Of course, the code in DialogBox event can be extended to handle other modules.

Place the code immediately below in the “Common script” area:

' ************************** GLOBAL VARIABLES ************************
'
Dim gv_BugInitCalledFromDialogBox
gv_BugInitCalledFromDialogBox = False
' ********************************************************************

Sub DialogBox(DialogBoxName, IsOpen)
  'Use ActiveModule and ActiveDialogName to get
  'the current context.
  On Error Resume Next

  If DialogBoxName = "New Bug" And IsOpen Then
    ' The "New Defects" button is clicked...

    ' Set a global variable so that the init function is not
    ' executed twice when clicking the "New Defect" button.
    gv_BugInitCalledFromDialogBox = True
    CUSTOM_BUG_Init

  ElseIf DialogBoxName = "Bug Details" And IsOpen Then
    ' An existing Defects record is opened; does not fire when
    ' selecting a defect in the defects grid
  End If

  On Error GoTo 0
End Sub

Place the code immediately below in the “Defects module script” area:

Sub CUSTOM_BUG_Init
  On Error Resume Next

  ' Add code that occurs every time a "New Defect" window is opened
  If Bug_Fields.Field("BG_BUG_ID").IsNull Then ' A new Defect
    CUSTOM_BUG_ClearRecord
  Else  ' An existing record
    ' Code that executes when an existing record is opened
  End If

  ' Add code to set the position, visibility, and read only
  ' attributes of the fields.

  ' Reset the global variable so Bug_New can execute after the
  ' "Submit" button is clicked.
  gv_BugInitCalledFromDialogBox = False

  On Error GoTo 0
End Sub

Sub CUSTOM_BUG_ClearRecord
  On Error Resume Next

  ' Clear all fields on the form.
  For i=0 To Bug_Fields.Count
    Bug_Fields.FieldById(i).Value = Null
  Next

  On Error GoTo 0
End Sub

Sub Bug_New
  On Error Resume Next

  ' If the Init function has not been called from the DialogBox,
  ' run it. This will execute after the "Submit" button is clicked.
  If gv_BugInitCalledFromDialogBox = False Then
    CUSTOM_BUG_Init
  End If

  On Error GoTo 0
End Sub

Sub Bug_MoveTo
  On Error Resume Next

  CUSTOM_BUG_Init

  On Error GoTo 0
End Sub

Is your standard workflow complex enough that this method will need to be utilized in your next workflow customization project, or do you plan to implement this code in your existing workflow? Have you already recognized this “feature” as a drawback in your existing workflow? Have you used other methods to accomplish the same task? Let us know by leaving a comment below.

Back to Blog