IBM Support

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

Question & Answer


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.

[{"Product":{"code":"SSSH5A","label":"Rational ClearQuest"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Designer - Hooks","Platform":[{"code":"PF033","label":"Windows"}],"Version":"8.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
21 March 2021

UID

swg21666202