How to write a Perl hook in IBM Rational ClearQuest to change the state from Submitted to Assigned

Technote (FAQ)


Question

How do you write a Perl hook in IBM Rational ClearQuest to change the state from Submitted to Assigned, if assignee field has some value at the time of record submission?

Cause

You would like to design your schema where a hook code should automatically change the state from Submitted to Assigned; if assignee field has some value at the time of record submission.

Answer

A Notification Perl hook code at action Submit can be written to achieve this requirement.

Procedure:

  1. Login to ClearQuest Designer with the role admin

  2. Click on Record Types > Navigate to the Record Type (For example Defect) > States And Actions > Actions > Submit

  3. Double click on Submit action, this will show all the Actions in right side panel

  4. Select the row of Submit action and click on the cell under the Notification column. It will open a drop down button, click on it and select SCRIPTS -> Add Perl Script

  5. This will Open the Notification Subroutine in Perl Script Editor

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

    # End User Code
    }

  6. Place the following code within this subroutine before # End User Code

    ****************************
    $sessionObj = $entity->GetSession();
    my $currstateobj = $entity->GetFieldValue("State");
    my $currstate = $currstateobj->GetValue();
    if ($currstate eq "Submitted")
    {
    my $assigneeobj = $entity->GetFieldValue("Assignee");
    my $assignee = $assigneeobj->GetValue();
    if ($assignee)
    {
    my $idobj = $entity->GetFieldValue("id");
    my $id = $idobj->GetValue();
    $entityToEdit = $sessionObj->LoadEntity("defect", $id);
    $sessionObj->EditEntity($entityToEdit, "Assign");
    $status = $entityToEdit->Validate();
    if ($status == "")
    {
    $entityToEdit->Commit();
    }
    else
    {
    $entityToEdit->Revert();
    }
    }
    }
    ****************************

  7. Save the work and perform Validation and check for errors

  8. If no errors, perform a Test Work

  9. Verify in the Test Database, if it is working as expected

  10. Once verified in the Test Database, CheckIn the Schema and Upgrade the Database

Note -

In the Above example we have made a few considerations:
  • Hook code should move the state from Submitted to Assigned.

  • There are NO Mandatory fields when moving from Submitted to Assigned State.

  • Record type is Defect.

  • Action name which changes the state from Submitted to Assigned is Assign.

Rate this page:

(0 users)Average rating

Document information


More support for:

Rational ClearQuest
Designer - Hooks

Software version:

8.0.1

Operating system(s):

Windows

Reference #:

1666202

Modified date:

2014-03-04

Translate my page

Machine Translation

Content navigation