Thursday, August 16, 2012

Sending Email from the Quality Center Workflow


 Sending an E-Mail from the Workflow


Purpose: The following code template allows sending any object in TestDirector (Defect, Test, etc.) by e-mail. The code can be used to extend the automatic mail notifications with custom conditions, not available for Send All Qualified. The template uses TestDirector mailing functions.
Code Location:  The code for the each object should be placed in the script of the corresponding module. For example: SendDefect function should be placed in Defects module.

Arguments:
iObjectId – The ID of the object that should be sent (see the note below on how to obtain the object ID).
strTo – The TestDirector names or e-mails of the people that will appear in To field of the e-mail (the names and e-mails should be separated by semicolon. For example: “user@domain.com;admin;alice_td”).
strCc – The TestDirector names or e-mails of the people that will appear in Cc field of the e-mail (the names and e-mails should be separated by semicolon. For example: “user@domain.com;admin;alice_td”). Specify an empty string (“”) to omit this parameter.
strSubject – The e-mail Subject. Specify an empty string (“”) to omit this parameter.
strComment – The e-mail comment (will appear at the top of the e-mail). Specify an empty string (“”) to omit this parameter.
Notes:
1. The object ID value can always be retrieved using the {Object}_Fields collection, by retrieving the Value property of the ID field. The example below shows how to retrieve the Ids of Defect, Test and Requirement:

          ’ Defect ID – for SendDefect
          Bug_Fields(“BG_BUG_ID”).Value
          ’ Test ID – for SendTest
          Test_Fields(“TS_TEST_ID”).Value
          ’ Requirement ID – for SendReq
          Req_Fields(“RQ_REQ_ID”).Value
2. The templates for Defect, Test and Requirement are provided. However the function may be used to work with any object that has Mail function.
3. The third parameter in Mail function allows specifying e-mail options. In the templates below this parameter is hard-coded (its value 2 means that the object History will be sent). However you can change this value to any of the values of TDMAIL_FLAGS. You can use sum to combine the mail properties. For example: 1 – means “send attachments”; 2 – means “send history”. In order to send the mail with attachments and history, specify 3 for this argument.

Return Value:  None

Code Template:

Sub SendDefect (iObjectId, strTo, strCc,
     strSubject, strComment)
On Error Resume Next
Dim objBugFactory, objBug
Set objBugFactory = TDConnection.BugFactory
Set objBug = objBugFactory.Item(iObjectId)
objBug.Mail strTo, strCc, 2, strSubject, strComment
Set objBug = Nothing
Set objBugFactory = Nothing
PrintError “SendDefect
On Error GoTo 0
End Sub
''''''''''''''''''''''''''''''''''''''''''
Sub SendTest (iObjectId, strTo, strCc,
     strSubject, strComment)
On Error Resume Next
Dim objTestFactory, objTest
Set objTestFactory = TDConnection. TestFactory
Set objTest = objTestFactory.Item(iObjectId)
objTest.Mail strTo, strCc, 2, strSubject, strComment
Set objTest = Nothing
Set objTestFactory = Nothing
PrintError “SendTest
On Error GoTo 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''
Sub SendRequirement (iObjectId, strTo, strCc,
     strSubject, strComment)
On Error Resume Next
Dim objReqFactory, objReq
Set objReqFactory = TDConnection.ReqFactory
Set objReq = objReqFactory.Item(iObjectId)
objReq.Mail strTo, strCc, 2, strSubject, strComment
Set objReq = Nothing
Set objReqFactory = Nothing
PrintError “SendRequirement
On Error GoTo 0
End Sub
''''''''''''''''''''''''''''''''''''''''
Usage Example: In the following example when the test status is changed, the e-mail notification is sent to the designer of the test, cc to all the members of the [QA Testers] group.

          Sub TestPlan_Test_FieldChange(FieldName)
On Error Resume Next
Dim strSubject, strComment
If FieldName = "TS_STATUS" Then 
          strSubject = “Test Change Notification” & _
                             “ for project “ & TDConnection.ProjectName & _
                             “ in domain “ & TDConnection.DomainName
          strComment = “The user “ & User.FullName & _
 “ changed the status of the test ” & _
 Test_Fields(“TS_NAME”).Value & _
 “ to “ & Test_Fields(“TS_ STATUS”).Value
                   SendTest Test_Fields("TS_TEST_ID").Value, _
                                 Test_Fields(“TS_RESPONSIBLE”).Value, “[QA Testers]”, _
                                 strSubject, StrComment
          End If
On Error GoTo 0
End Sub

Error Handling


. Error Handling



  • Use “On Error Resume Next” statement at the beginning of each procedure and function.
  • Use “On Error GoTo 0” at the end of each procedure or function
  • Show errors to the user in some standard message box



Compare the following code fragments:

If Bug_Fields(“BG_SEVERITY”).Value = “4-Urgent” Then
        Bug_Fields(“BG_PRIORITY”).Value = “4-Urgent”
End If
On Error Resume Next
...
If Bug_Fields(“BG_SEVERITY”).Value = “4-Urgent” Then
        Bug_Fields(“BG_PRIORITY”).Value = “4-Urgent”
End If
...
PrintError “SomeSub”
On Error GoTo 0

The both code fragments will work the same way when no problems arise during the code execution. But what happens if, for example, the user has no permissions to modify BG_PRIORITY field? The left fragment will not update the field and will cause the browser crash. The second will not update the field, but it will show the correct error to the user and the browser will not crash.

Thursday, March 1, 2012

How to Know the audit log entries of a Bug

Below is the query which will provide the complete information of a bug. This info will be extracted from the audit table. You need to update the bug id in the where for which you wanted the info.
SELECT AL.AU_USER, AL.AU_TIME, AP.AP_PROPERTY_NAME,
       AP.AP_NEW_VALUE, AP.AP_NEW_LONG_VALUE, AP.AP_NEW_DATE_VALUE,AL.AU_ACTION
FROM AUDIT_LOG AL, AUDIT_PROPERTIES AP, BUG B
WHERE (AL.AU_ACTION_ID = AP.AP_ACTION_ID)
  AND (TO_CHAR(B.BG_BUG_ID) = TO_CHAR(AL.AU_ENTITY_ID))
  AND (B.BG_BUG_ID = <Bug Id>)
  AND (AL.AU_ENTITY_TYPE = 'BUG')
ORDER BY AU_TIME ASC

Quality Center Project Migration

I just wanted to share my experience in migrating a project from QC9.2 to QC10
We have got a requirement from the user  to migrate QC9.2 project using SQL server 2005 as backend to QC10 Oracle. I had tried couple of options to migrate this and finally finalized the below process to complete this task. We even contacted the HP to know the best approach but unfortunately they don’t have process to accomplish this.

1)      We have created DB user (QC) on QC9.2  SQL server 2005.
2)      Added SQL Server DB server in QC10 server using DB servers Tab
3)      Created a project in QC10 using SQL Server 2005 DB server which was added in the previous step.
4)      Created a project in  QC9.2  by selecting make a copy of existing project.
5)      Removed project from site admin and Updated the db.xml file of the project which is created in step 2 with the project schema which is created step 4.
6)      Upgraded the project in QC10 by following steps (Verify, Repair and Upgrade).
7)       Exported the upgraded project to generate .qcp file.
8)      Imported the upgraded file by selecting Oracle as DB ( Migration from SQL server 2005 to Oracle was completed in this step by tool itself).
9)      Copied the attachments folder from QC9.2 NAS to Our QC10 NAS.