Creating a dependent choice list

HCL Compass allows you to specify that the values of one field (dependent field) depend upon the values of another field (parent field). This is accomplished by defining a Choice_List hook on the dependent field that sets its choice list based upon the value of the parent field.

In this example, you have two fields: Platform and Version. Platform is the parent field and has a constant (enumerated) choice list. Version is the dependent field which calculates the appropriate choice list based on the value of Platform.

Version's Choice list hook gets recalculated every time Platform changes because its Recalculate Choice List option is set.

Note that any field change triggers the hook to be rerun.

  • If any field changes, all fields with Recalculate Choice List set will rerun their Choice List hook, even if the choice list does not depend on the changed field.
  • To have the choice list update only when its dependent field actually changes, use the GetFieldOriginalValue method to check the parent field.

In general, Recalculate Choice List should only be set for fields which have a Choice List Hook defined, and should not be set on those that do not.

This Choice List Hook code determines the enumerated content of the choice list based upon the value of the parent field, Platform.

In the following examples:

  • The value of the parent field is a SHORT_STRING data type. For VBScript, during the CASE selection, the enumerated values of Platform must to be identical to the string, shown here, including the blank spaces. Otherwise, the related list is not generated.
  • Before executing this code, the choice list is defaulted to an empty list. If none of these cases match, there will be no choice list.

VBScript


' Add field choices for platforms
Dim platform

platform = GetFieldValue("platform").GetValue ()

select case platform

   case "Windows 2000"

      choices.AddItem ("Professional")

      choices.AddItem ("Professional SP1")

      choices.AddItem ("Server")

      choices.AddItem ("Server SP1")

   case "Windows NT Server"

      choices.AddItem ("4.0")

      choices.AddItem ("4.0 SP6A")

   case "Windows 98"

      choices.AddItem ("Win98")

end select 

Perl


my $platform;

$platform = ($entity->GetFieldValue("platform"))->GetValue();

if ($platform eq "Windows NT Workstation") {

   push(@choices, "3.51", "4.0", "4.0 SP2", "4.0 SP3");

} else {

   if ($platform eq "Windows NT Server") {

               push(@choices, "4.0", "4.0 SP3");

   } else {

        if ($platform eq "Windows 95") {

               push(@choices, "Win95");

        } else {

               push(@choices, " ");

      }

 }

}