UPDATE: This blog posting has become obsolete with the introduction of Calculations in Dynamics AX 2012 R2 CU6. Please see the following blog posting for more details.
http://blogs.msdn.com/b/axmfg/archive/2013/07/01/product-configurator-new-calculations-concept.aspx
The constraint based product configurator was released in Dynamics AX 2012. The bulk of the constraint logic can be built using Microsoft Solver Foundation logic, as described in the following technet article.
http://technet.microsoft.com/EN-US/library/hh278332.aspx
There are some limitations to what can be accomplished through the solver foundation. For example, product configurator does not support the use of decimal values in constraint calculations and as a result prohibits many calculations involving multiplication and division.
One way to meet these requirements is to make use of the newly introduced PCAdaptor class. The following example shows how to use this class to calculate a decimal quantity for a BOM Line as the square of an integer divided by 3. In many cases thistype of calculation would result in decimal values, so it could not be accommodated using the solver foundation logic.
Our calculation will be:
BOM Quantity = (Integer1^2)/3
We will be using a very basic product configuration that consists of one attribute and no constraints. This example uses the contoso USA demo data .
Basic Product Model Setup
Product Model: CalculationExample
Attributes
Name
Solver Name
Description
Attribute Type
INTEGER1
IntegerDomainHTSLight
BOM Lines
Item Number
Quantity
1101 Name
1101Description
1101
1
X++ Code to calculate the required quantity.
In order to call the API we will need to create a new class in the AOT that extends the PCAdaptor class. I’ve created a new class called ModelCalcExample. The classDeclaration method for this class is shown below. Note that thePCAdaptorExtensionAttribute must be used to indicate that this class is associated with my CalculationExample product model.
[PCAdaptorExtensionAttribute('CalculationExample')]//Model Name
public class ModelCalcExample extends PCAdaptor
{
}
Next I will need to include some code in the run method of my class. This code will execute after Ihave made all attribute selections and click on the Ok button.
public void run()
str 100 INT1;
real QTY;
PCAdaptorAttribute attr; PCAdaptorRootComponent rootComponent;
rootComponent = this.parmProductConfigurationModel().getRootComponent();
attr = rootComponent.getAttribute('INTEGER1');
INT1 = attr.getValueAsLocalizedString();
QTY = (str2int(INT1)*str2int(INT1))/3;
if(QTY)
{ rootComponent.getBOMLine('1101 Name').parmturnoverquantity(QTY);
Now that we’ve written this code, we can test the results. If you assign this productconfiguration model to a configurable item, and test using an integer value of13 you should get a 1 line BOM for your item that contains Item Number 1101with a quantity of 56.3333.
This is only one example of what can be done using the API with constraint base product models. There are many other parameter values that canbe set on both BOM’s and Routes. Some examples include calculating the run time of a route operation, setting thescrap factor on a BOM line, and setting route operation priority. You can get a feel for the possibilities byreviewing the methods within the PCAdaptorBOMLine and PCAdaptorRouteOperation classes.