IBM Support

How to write a Value Change Perl hook in Rational ClearQuest to assign a value to another field and make it Read Only

Technote (FAQ)


How do you write a Value Change Perl hook in IBM Rational ClearQuest to assign a value to another field and make it Read Only?


You would like to design your schema where a field gets it's value based on a value selected in another field.


This hook code is valid for StateBased Record Types only. You should have two fields.

In the example below the fields considered are:

  • Component (a drop-down field)
  • SubComponent (a text box).

If you select Comp1 value from the drop-down of the field   Component , the field SubComponent should have a value SubComp1 and it should turn as a ReadOnly field.


  1. Login to ClearQuest Designer with the role admin

  2. Click on Record Types > Navigate to any Record > Fields.

  3. Select the row Component and column as Value Changed.

  4. Click and select SCRIPTS-PERL

    This will open Perl Script Editor and you will get a new Subroutine


    sub component_ValueChanged {
       my($fieldname) = @_;
       # $fieldname as string scalar
       # record type name is Defect
       # field name is customer
       # This hook will be run each time the field's value changes.
       # This hook runs before the new value is validated so be aware
       # the new value may not be valid.
       # Example:
       #   my $op_sys = $entity->GetFieldValue($fieldname)->GetValue();
       #   if ($op_sys eq "windows") {
       #      $entity->SetFieldValue("os_version", "NT 4.x");
       #      <etc.>

  5. Place the below code within the above subroutine -

    # Value Change Hook code for "Component
    $session = $entity->GetSession();
    my($compname) = $entity->GetFieldValue($fieldname)->GetValue() ;
    if ($compname eq "Comp1" )
    $entity->SetFieldValue("SubComponent", "SubComp1"); $entity->SetFieldRequirednessForCurrentAction("SubComponent",$CQPerlExt::CQ_READONLY);

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

  7. If no errors, perform a Test Work.

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

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

Document information

More support for: Rational ClearQuest
Designer - Hooks

Software version: 7.1.2,,

Operating system(s): Windows

Reference #: 1643420

Modified date: 10 February 2014

Translate this page: