How to send email notifications using CQMailMsg in ClearQuest

Technote (FAQ)


Question

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

Cause

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

Answer

Procedure:


Disclaimer

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($result);
    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();
    $mailmsg->AddTo($Email);

    # Write the subject line of the email here
    $Sub="A new Defect";
    $mailmsg->SetSubject($Sub);

    # Write the body of the email here
    $body = "Dear User, A new Record has been submitted.\n\n";
    $mailmsg->SetBody($body);

    # Sending the email
    $mailmsg->Deliver();
    CQMailMsg::Unbuild($mailmsg);
    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

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

Related information

Sening an e-mail notification using Perl Hook

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

Rational ClearQuest
Designer - Hooks

Software version:

7.1.2, 7.1.2.3, 7.1.2.5

Operating system(s):

Windows

Reference #:

1641874

Modified date:

2013-07-01

Translate my page

Machine Translation

Content navigation