IBM Support

How to send email notifications using CQMailMsg in ClearQuest

Question & Answer


How do you send Email notifications through a Perl hook code which uses CQMailMsg in IBM Rational ClearQuest?


You require a method to send customized emails in IBM Rational ClearQuest.




All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

  1. Log on to Rational ClearQuest Designer as a user with Schema Designer or Super User privilege.

  2. Click Record Types > Record > Record Scripts > Perl

  3. Right click on Perl and click Add

  4. Provide a name for the script.
    For example - Email_Notify

  5. Double click Email_Notify
    This will open a subroutine

  6. Add the following code to this subroutine:

    # This code is finding the Submitter's  email (User who will submit the Record) and will send email only to that Submitter.
    # Further it can be configured to send email notification to other users also

    sub Defect_Email_Notify {
    my($param) = @_;
    # record type name is Defect
    if (ref ($param) eq "CQEventObject") {
            # add your CQEventObject parameter handling code here
    } elsif (ref (\$param) eq "SCALAR") {
           # add your scalar parameter handling code here
           # The Web clients support scalar paramter type only,
          # so the hook code added in the above section, needs to be duplicated here
      } else {
           # add your handling code for other type parameters here, for example:
           # die("Unknown parameter type");
    $name = $entity->GetFieldValue("Submitter")->GetValue();
    $EntityObj = $session->GetEntity("users",$name);
    $Email = $EntityObj->GetFieldValue(email)->GetValue();

    my $mailmsg = CQMailMsg::Build();

    # Write the subject line of the email here
    $Sub="A new Defect";

    # Write the body of the email here
    $body = "Dear User, A new Record has been submitted.\n\n";

    # Sending the email
    return $result;

  7. Save

  8. Click Record Types > Record > States And Actions > Actions

  9. Double click Actions to display the Actions grid

  10. Click the Notification column to the action you want to add the notification hook
    Note: In this example it is "Submit" Action

  11. Click the arrow icon and click SCRIPTS > PERL

  12. Add the following code:

    sub Defect_Notification {
       my($actionname, $actiontype) = @_;
       # $actionname as string scalar
       # $actiontype as long scalar
       # action is Submit
       # record type name is Defect
       # Post-commit notifications about actions may be handled here.

    $entity->FireNamedHook("Email_Notify", "");


  13. Save

  14. Perform Validation and check if you see any errors.
    If no errors, perform a Test Work

  15. Verify in the Test Database, if the code is working as expected

  16. CheckIn the Schema and Upgrade the Database

    Ensure you have correct settings configured for emails in IBM Rational ClearQuest Client.

[{"Product":{"code":"SSSH5A","label":"Rational ClearQuest"},"Business Unit":{"code":"BU050","label":"BU NOT IDENTIFIED"},"Component":"Designer - Hooks","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.1.2;;","Edition":""}]

Document Information

Modified date:
16 June 2018