Sorting Requirements in Quality Center

  • KM505626
  • 21-Oct-2008
  • 21-Oct-2008

Summary

Sorting Requirements in Quality Center is cumbersome with unexpected results

Question

Using the QC GUI its troublesome to resort Requirements at the same level under the same parent item in the order desired. Clicking and dragging or using copy/paste is somewhat useful but is cumbersome and commonly delivers an unintended order.

Answer

Note: The following script is provided for example purposes only. It is not supported by Hewlett Packard.


The below solution allows Requirements under the same parent to be reordered.


1)      Create two Toobar Buttons in the Requirements module.
     a.       Assign an “up-arrow” icon to one of the buttons and give it the action of “actMoveReqUp”
     b.      Assign an “down-arrow” icon to one of the buttons and give it the action of “actMoveReqDown”
 
2)      In the Script Editor, Common Script add the following code to the “Function ActionCanExecute(ActionName)”


Function ActionCanExecute(ActionName)
 'Use ActiveModule and ActiveDialogName to get
 'the current context.
 ' For example:
 ' if ActiveModule = "Requirements" then
 '     msgbox "Action in Requirements module"
 ' end if
 ActionCanExecute = True
 Dim intReqID
 Dim intReqFatherID
 intReqID = Req_Fields.Field("RQ_REQ_ID").Value
 intReqFatherID = Req_Fields.Field("RQ_FATHER_ID").Value
 If ActionName = "actMoveReqUp" Then
    If len(intReqID) > 0 and len(intReqFatherID) > 0 then
       If MoveReqUp(intReqID) = True then
          Actions.Action("actFilterRefresh").Execute
       End If
    End If
 ElseIf ActionName = "actMoveReqDown" Then
    If len(intReqID) > 0 and len(intReqFatherID) > 0 then
       If MoveReqDown(intReqID) = True then
          Actions.Action("actFilterRefresh").Execute
       End If
    End If
 End If
End Function
 
3)      Add a new Function “MoveReqUp” to handle the process of moving a requirement up
 
Function MoveReqUp(intReqID)
    Dim td
    Dim rFact
    Dim rItem
    Dim rItemA
    Dim strSQL
    Dim cmd
    Dim mRSData
    Dim intFatherID
    Dim intTmpIDA
    Dim intValueA
    Dim intValueB
    Set td = TDConnection
    Set rFact = td.ReqFactory
    Set rItem = rFact.Item(intReqID)
    intFatherID = rItem.Field("RQ_FATHER_ID")
    strSQL = "SELECT RQ_REQ_ID, RQ_FATHER_ID, RQ_ORDER_ID "
    strSQL = strSQL & "FROM REQ "
    strSQL = strSQL & "WHERE RQ_FATHER_ID = " & intFatherID
    strSQL = strSQL & " ORDER BY RQ_ORDER_ID"
    Set cmd = td.Command
    cmd.CommandText = strSQL
    Set mRSData = cmd.execute
    If mRSData.RecordCount > 1 Then
       With mRSData
         .First
         Do while .EOR = False
             if cstr(.FieldValue(0)) = cstr(intReqID) and .FieldValue(2) > 1 then
                intValueA = .FieldValue(2) - 1
                intTmpIDA = .FieldValue(0)
                Set rItemA = rFact.Item(.FieldValue(0))
                   rItemA.Field("RQ_ORDER_ID") = 0
                   rItemA.Post
                   .Prev
                   intValueB = .FieldValue(2) + 1
                   Set rItemA = rFact.Item(.FieldValue(0))
                   rItemA.Field("RQ_ORDER_ID") = intValueB
                   rItemA.Post
                   Set rItemA = rFact.Item(intTmpIDA)
                   rItemA.Field("RQ_ORDER_ID") = intValueA
                   rItemA.Post
                   Exit Do
             End If
            .Next
         Loop
       End With
    End If
    Set td = Nothing
    Set rFact = Nothing
    Set rItem = Nothing
    Set rItemA = Nothing
    Set strSQL = Nothing
    Set cmd = Nothing
    Set mRSData = Nothing
    Set intFatherID = Nothing
    Set intTmpIDA = Nothing
    Set intValueA = Nothing
    Set intValueB = Nothing
    MoveReqUp = True
End Function
 
4)      Add another new Function “MoveReqDown” to handle the process of moving a Requirement down
 
Function MoveReqDown(intReqID)
    Dim td
    Dim rFact
    Dim rItem
    Dim rItemA
    Dim strSQL
    Dim cmd
    Dim mRSData
    Dim intFatherID
    Dim intTmpIDA
    Dim intValueA
    Dim intValueB
    Set td = TDConnection
    Set rFact = td.ReqFactory
    Set rItem = rFact.Item(intReqID)
    intFatherID = rItem.Field("RQ_FATHER_ID")
    strSQL = "SELECT RQ_REQ_ID, RQ_FATHER_ID, RQ_ORDER_ID "
    strSQL = strSQL & "FROM REQ "
    strSQL = strSQL & "WHERE RQ_FATHER_ID = " & intFatherID
    strSQL = strSQL & " ORDER BY RQ_ORDER_ID"
    Set cmd = td.Command
    cmd.CommandText = strSQL
    Set mRSData = cmd.execute
    If mRSData.RecordCount > 1 Then
       With mRSData
         .Last
         If cstr(.FieldValue(0)) = cstr(intReqID) Then Exit Function
         msgbox "Field: " & cstr(.FieldValue(0)) & ", " & "ID: " & cstr(intReqID)
         .First
         Do while .EOR = False
             if cstr(.FieldValue(0)) = cstr(intReqID)then
                intValueA = .FieldValue(2) + 1
                intTmpIDA = .FieldValue(0)
                Set rItemA = rFact.Item(.FieldValue(0))
                   rItemA.Field("RQ_ORDER_ID") = 0
                   rItemA.Post
                   .Next
                   intValueB = .FieldValue(2) - 1
                   Set rItemA = rFact.Item(.FieldValue(0))
                   rItemA.Field("RQ_ORDER_ID") = intValueB
                   rItemA.Post
                   Set rItemA = rFact.Item(intTmpIDA)
                   rItemA.Field("RQ_ORDER_ID") = intValueA
                   rItemA.Post
                   Exit Do
             End If
            .Next
         Loop
       End With
    End If
    Set td = Nothing
    Set rFact = Nothing
    Set rItem = Nothing
    Set rItemA = Nothing
    Set strSQL = Nothing
    Set cmd = Nothing
    Set mRSData = Nothing
    Set intFatherID = Nothing
    Set intTmpIDA = Nothing
    Set intValueA = Nothing
    Set intValueB = Nothing
    MoveReqDown = True
End Function
 
 
*The example software is experimental and is provided as a courtesy, free of charge, “AS-IS” by Hewlett-Packard Development Company, L.P. (“HP”). HP shall have no obligation to maintain or support this software. HP MAKES NO EXPRESS OR IMPLIED WARRANTY OF ANY KIND REGARDING THIS SOFTWARE. HP SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER BASED ON CONTRACT, TORT OR ANY OTHER LEGAL THEORY, IN CONNECTION WITH OR ARISING OUT OF THE FURNISHING, PERFORMANCE OR USE OF THIS SOFTWARE