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

Question & Answer


Question

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?

Cause

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

Answer

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.

PROCEDURE:

  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

    Example:

    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

[{"Product":{"code":"SSSH5A","label":"Rational ClearQuest"},"Business Unit":{"code":"BU004","label":"Hybrid Cloud"},"Component":"Designer - Hooks","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.1.2;7.1.2.3;7.1.2.7","Edition":""}]

Document Information

Modified date:
16 June 2018

UID

swg21643420