Creating a dependent choice list
DevOps Plan 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
GetFieldOriginalValuemethod 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.
- 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.
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, " ");
}
}
}