Newer Version Available

This content describes an older version of this product. View Latest

Table Constraints

The table constraint in Constraint Modeling Language (CML) is used to define a set of valid combinations of values for two or more attributes. These combinations are specified in rows within the constraint definition.

The table constraint has this syntax:

1table(variable, …, variable, {value, .. value}, …, {value, …, value});

Each row inside {} defines a valid combination of values.

Example: Table Constraint

In this example:

  • Variables: The attributes Voltage and DutyRating are listed as the columns for the table.
  • Table Rows: Each row defined within the curly braces ({}) specifies a valid combination. For instance, {"7976/13800", "Continuous Power (COP)"} is a valid pairing.
  • Enforcement: If a user attempts to select a high voltage ("7976/13800") while choosing a Prime Power rating ("Prime Power (PRP)"), the table constraint is violated, and the engine displays the error message: "Selected Voltage is not compatible with the required Duty Rating."
1// --- Component Types ---
2type GeneratorSet {
3// 1. Attributes whose values must align according to the table
4string Voltage = ["220/380", "277/480", "7976/13800"];
5string DutyRating = ["Prime Power (PRP)", "Continuous Power (COP)", "Emergency Standby Power (ESP)"];
6// 2. Table Constraint
7// Defines valid combinations where Voltage and DutyRating are mutually dependent.
8constraint validOperationalModes(
9table(
10Voltage,
11DutyRating,
12{"220/380", "Prime Power (PRP)"},
13{"220/380", "Continuous Power (COP)"},
14{"220/380", "Emergency Standby Power (ESP)"},
15{"277/480", "Prime Power (PRP)"},
16{"277/480", "Emergency Standby Power (ESP)"},
17{"7976/13800", "Continuous Power (COP)"}
18),
19"Selected Voltage is not compatible with the required Duty Rating."
20);
21}

Import Data from a Salesforce Object to Populate a Table Constraint

Import data from a standard or custom Salesforce object to use in a table constraint in a constraint model. The imported data populates the columns and rows in the table constraint in CML, and saves you the step of manually entering the data.

To import data from a Salesforce object, first assign Read, Create, Edit, and Delete permissions for the object to the Constraint Rules Engine Licenseless permission set. See Import Data from Salesforce Objects to Use in Constraint Models in Salesforce Help.

In CML, use the SalesforceTable keyword and the syntax shown here to import data from a Salesforce object. This example uses the GeneratorSet type to constrain the calculated running capacity (gc_runningKw) based on a user's selection of the nominal output (Nominal_Power_Output), referencing an external Salesforce custom object named PowerCst__c.

Example: Imported Table Constraint

1type GeneratorSet {
2// 1. Attribute storing the user-selected power output (String)
3string Nominal_Power_Output = ["100 kW", "300 kW", "500 kW", "700 kW"];
4// 2. Attribute storing the resulting Running kW (Decimal, calculated)
5@(configurable = false, defaultValue = "0")
6decimal(2) gc_runningKw;
7// Constraint ensures the pairing of Nominal_Power_Output and gc_runningKw is found in the imported Salesforce table.
8constraint(
9table(
10Nominal_Power_Output, gc_runningKw,
11SalesforceTable("PowerCst__c","Nominal__c,Running__c")
12)
13);
14}

Explanation of the Imported Table

The table constraint ensures that the selected values for Nominal_Power_Output and gc_runningKw must form one of the valid combinations defined in the external source.

  • Table (Nominal_Power_Output, gc_runningKw, ...): These are the CML attributes whose values must correlate. They define the columns of the required combination table.
  • Salesforce Table ("PowerCst__c", "Nominal__c,Running__c"): This function keyword directs the constraint engine to import data from the Salesforce custom object PowerCst__c.
  • Field Mapping: The fields specified ("Nominal__c,Running__c") define the columns in the Salesforce object that correspond to the CML attributes listed in the table function. Nominal__c maps to Nominal_Power_Output, and Running__c maps to gc_runningKw.