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:
Note -
In the Above example we have made a few considerations:
Procedure:
- Login to ClearQuest Designer with the role admin
- Click on Record Types > Navigate to the Record Type (For example Defect) > States And Actions > Actions > Submit
- Double click on Submit action, this will show all the Actions in right side panel
- 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
- 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
}
- 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();
}
}
}
****************************
- Save the work and perform Validation and check for errors
- If no errors, perform a Test Work
- Verify in the Test Database, if it is working as expected
- 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"}}]
Was this topic helpful?
Document Information
Modified date:
21 March 2021
UID
swg21666202