Consolidate Multiple Default Configurations

Apply dynamic, overridable default quantities to a single component based on multiple states of a driving attribute, using one derived variable and a single setdefault rule.

Apply dynamic, overridable default quantities to a single component based on multiple possible states of a driving attribute. This process avoids rule conflicts where only the last rule evaluates.

When multiple setdefault rules target the same assignment in the RHS, evaluations can conflict. For example, a conflict can result when the rule targets the same relation and type, such as accessories[Accessory] == .... The condition side can use different expressions, but if the rules resolve to the same target on the assignment side, behavior can become order-dependent and lead to inconsistent outcomes.

For example, if you want to set a default for the quantity of Accessories based on the selected DutyRating of a Generator Set, writing three separate setdefault rules causes inconsistent behavior depending on the quantity changes of the accessories.

To prevent the conflict, consolidate the conditional logic into a single derived variable using nested ternary expressions, such as ? :. Then, apply a single setdefault rule using that newly derived variable to drive the relation’s quantity.

This example shows the recommended process, consolidating the logic into a single variable and rule.

1type GeneratorSet : LineItem {
2    string DutyRating = ["Prime Power (PRP)", "Continuous Power (COP)", "Emergency Standby Power (ESP)"];
3
4    relation accessories : Accessory[1..99] {
5        default Accessory(1);
6    }
7
8    // 1. Consolidate the conditional logic into a single integer variable
9    int defaultAccessoryQty = (DutyRating == "Prime Power (PRP)") ? 2 : ((DutyRating == "Continuous Power (COP)") ? 4 : 6);
10
11    // 2. Create a dynamic informational message
12    string infoMsg = DutyRating + " accessory default overridden";
13
14    // 3. Apply a single setdefault rule using the derived variable
15    setdefault(
16        DutyRating in ["Prime Power (PRP)", "Continuous Power (COP)", "Emergency Standby Power (ESP)"],
17        accessories[Accessory] == defaultAccessoryQty,
18        infoMsg
19    );
20}

Avoid the process shown in this example, which includes multiple conflicting setdefault rules.

1type GeneratorSet : LineItem {
2    string DutyRating = ["Prime Power (PRP)", "Continuous Power (COP)", "Emergency Standby Power (ESP)"];
3
4    relation accessories : Accessory[1..99] {
5        default Accessory(1);
6    }
7
8    // X AVOID: Multiple setdefault rules targeting the same relation.
9    // Only the last rule will reliably evaluate.
10    setdefault(DutyRating == "Prime Power (PRP)", accessories[Accessory] == 2, "PRP error");
11    setdefault(DutyRating == "Continuous Power (COP)", accessories[Accessory] == 4, "COP error");
12    setdefault(DutyRating == "Emergency Standby Power (ESP)", accessories[Accessory] == 6, "ESP error");
13}