Newer Version Available

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

External Variables

External variables are global Constraint Modeling Language (CML) variables defined within a virtual CML type.

See virtual in Type Annotations. The values for external variables are usually set by the environment that launches the constraint solver engine. Use external variables to import runtime data from the context header (such as Quote or Sales Transaction) into the configuration model, with the contextPath annotation to denote header fields, or with tagName annotation to denote lineItem fields. See External Variable Annotations section.

If the external variable isn't mapped to any external data source, it must have a default value. Otherwise, it may remain unbound and cause errors.

Here's a basic declaration syntax.

1extern int MAX_VALUE = 9999;
2extern decimal(2) threshold = 1.5;

Example: Using External Variables with Context Path Annotation

In this example, the constraint engine needs access to the quote header (Sales Transaction) field, which defines the shipping location to enforce region-specific compliance requirements. The contextPath annotation is used to map the field (SalesTransaction.ShippingCountry) to an external CML variable (ShippingCountry).

The CML variable name can be different from the context path value.

Note

1// External variable declaration with context path annotation
2@(contextPath = "SalesTransaction.ShippingCountry")
3extern string ShippingCountry; // ShippingCountry Value is pulled from the Quote/Order header

See the full example in Using ContextPath and tagName annotations.

External Variable Annotations

Here are the details of external variable annotations.

Annotation Possible Value Description
contextPath "SalesTransaction.<ST_FIELD>", where the sales transaction field is pulled directly from the context definition.

References sales transaction values directly from their context definition, such as account name, sales transaction total, or address. The contextPath annotation can only be used for header fields.

To create a variable linked to a SalesTransactionItem, use the tagName annotation to reference context tags on SalesTransactionItem within a type. See tagName in Variable Annotations.