Expression constraints and table constraints

Important

This content is archived and is not being updated. For the latest documentation, see Microsoft Dynamics 365 product documentation. For the latest release plans, see Dynamics 365 and Microsoft Power Platform release plans.

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack

This topic describes the use of expression constraints and table constraints. Constraints control the attribute values that you can select when you configure products for a sales order, sales quotation, purchase order, or production order. You can use expression constraints or table constraints, depending on how you prefer to build the constraints.

What are expression constraints?

Expression constraints are characterized by an expression that uses arithmetic and Boolean operators and functions. An expression constraint is written for a specific component in a product configuration model. It can't be reused by or shared with another component. However, the expression constraints for a component can reference attributes of the component's subcomponents. For information about how to create an expression constraint, see Create an expression constraint for a product component.

What are table constraints?

Table constraints list the combinations of values that are allowed for attributes when you configure a product. Table constraint definitions can be used generically. When you create a table constraint for a component in a product configuration model, you select a table constraint definition.

To create the combinations that are allowed, you add attributes of specific types to the components. Each attribute type has a specific value. For information about how to create a table constraint and how to add it to a product configuration model, see Create a table constraint and Add a table constraint to a component.

Example of a table constraint

This example shows how you can limit the configuration of a television to specific sizes and types for a seasonal offer.

This first table shows the sizes and types of televisions that are generally available for configuration. The television sizes and types are the values that are available for the TelevisionType and TelevisionSize attribute types.

Attribute

Attribute type

Values

Television

TelevisionSize

24, 36, 42, 48, 50

TelevisionType

Plasma, Projection, OLED, LCD

This next table shows the combinations that are defined by the TV seasonal offer table constraint. By using this table constraint, you can configure a Plasma television and a Projection television only in sizes 48 and 50, and you can configure an LCD television only in size 36.

Table constraint

Type

Size

TV seasonal offer

Plasma

48

Plasma

50

Projection

48

Projection

50

LCD

36

For more information about how to add attributes to components, see Add an attribute to a component.

You can create system-defined and user-defined table constraints. For more information about these types of table constraints, see About system-defined and user-defined table constraints.

What syntax should be used to solve constraints in Microsoft Dynamics AX?

You must use Optimization Modeling Language (OML) syntax when you write the constraints. Microsoft Dynamics AX uses Microsoft Solver Foundation constraint solver to solve the constraints. For more information, see Microsoft Solver Foundation.

Should I use table constraints or expression constraints?

You can use either expression constraints or table constraints, depending on how you prefer to build the constraint setup. You build up a table constraint as a matrix, whereas an expression constraint is an individual statement. When you configure a product, it doesn't matter what kind of constraint is used. The following example illustrates the difference between the two methods.

When you configure a product by using the following constraint setup, the combinations that are allowed are a product in the color Black and in size 30 or 50, and a product in the color Red and in size 20.

Table constraint setup

Color

Size

Black

30

Black

50

Red

20

Expression constraint

(Color == "Black" & (size == "30" | size == "50")) | (color == "Red" & size = "20")

Should I use operators or infix notation when I write expression constraints?

You can write an expression constraint either by using the available prefix operators or by using infix notation. For the operators Min, Max, and Abs, you can't use an infix notation. These operators are included as a standard in most programming languages.

What operators and infix notations can I use when I write expression constraints?

The following tables list the operators and infix notations that you can use when you write an expression constraint for a component in a product configuration model.

In the examples in this first table, you can see how to write an expression by using either infix notation or operators.

Operator

Description

Syntax

Examples

Implies

This is true if the first condition is false, the second condition is true, or both.

Implies[a, b], infix: a -: b

Operator: Implies[x != 0, y >= 0]

Infix notation: x != 0 -: y >= 0

And

This is true only if all conditions are true.

If the number of conditions is 0 (zero), it produces True.

And[args], infix: a & b & ... & z

Operator: And[x == 2, y <= 2]

Infix notation: x == 2 & y <= 2

Or

This is true if any condition is true.

If the number of conditions is 0 (zero), it produces False.

Or[args], infix: a | b | ... | z

Operator: Or[x == 2, y <= 2]

Infix notation: x == 2 | y <= 2

Plus

This sums its conditions.

If the number of conditions is 0 (zero), it produces 0.

Plus[args], infix: a + b + ... + z

Operator: Plus[x, y, 2] == z

Infix notation: x + y + 2 == z

Minus

This negates its argument.

This must have exactly one condition.

Minus[expr], infix: -expr

Operator: Minus[x] == y

Infix notation: -x == y

Abs

This takes the absolute value of its condition.

This must have exactly one condition.

Abs[expr]

Operator: Abs[x]

Times

This takes the product of its conditions.

If the number of conditions is 0 (zero), it produces 1.

Times[args], infix: a * b * ... * z

Operator: Times[x, y, 2] == z

Infix notation: x * y * 2 == z

Power

This takes an exponential.

This applies exponentiation from right to left. That is, it is right-associative, and therefore Power[a, b, c] is equivalent to Power[a, Power[b, c]]. Power can only be used with a positive constant as the exponent.

Power[args], infix: a ^ b ^ ... ^ z

Operator: Power[x, 2] == y

Infix notation: x ^ 2 == y

Max

This produces the largest condition.

If the number of conditions is 0 (zero), it produces Infinity.

Max[args]

Operator: Max[x, y, 2] == z

Min

This produces the smallest condition.

If the number of conditions is 0 (zero), it produces Infinity.

Min[args]

Operator: Min[x, y, 2] == z

Not

This produces the logical inverse of its condition.

This must have exactly one condition.

Not[expr], infix: !expr

Operator: Not[x] & Not[y == 3]

Infix notation: !x!(y == 3)

The examples in the following table show how to write an infix notation.

Infix notation

Description

x + y + z

Addition

x * y * z

Multiplication

x - y

Binary subtraction is translated the same as binary addition with a negated second.

x ^ y ^ z

Exponentiation with right associativity

!x

Boolean not

x -: y

Boolean implication

x | y | z

Boolean or

x & y & z

Boolean and

x == y == z

Equality

x != y != z

Distinct

x < y < z

Less than

x > y > z

Greater than

x <= y <= z

Less than or equal to

x >= y >= z

Greater than or equal to

(x)

Parentheses override default precedence.

Why don't my expression constraints validate correctly?

You can't use reserved keywords as solver names for attributes, components, or subcomponents in a product configuration model. The following list contains the reserved keywords that you can't use:

  • Ceiling

  • Element

  • Equal

  • Floor

  • If

  • Less

  • Greater

  • Implies

  • Log

  • Max

  • Min

  • Minus

  • Plus

  • Power

  • Times

  • Slot

  • Model

  • Decision

  • Goal

Don't see your question here?

We're working to include as many questions as we can, so that Microsoft Dynamics AX Help will be more useful to people just like you.

Tell us what question you would like to add to this topic. Send email to adocs@microsoft.com.