The Product Configurator configures products. The configuration’s setup drives the configured product’s price and delivery date. After this setup is complete, a user can open an order and add a default product to it. The user then configures the product using the PCRuntimeConfigurator form. When the user completes the configuration, Dynamics 365 places the final price and delivery date on the order line. Have you ever needed to calculate a configured product’s total price without user input? This blog post will help you.
When a user is configuring the product, the Product Configurator is modifying an XML document that stores all of the user’s selections. Unfortunately, getting the XML document is the easy part. We need to parse through the XML document to obtain any useful information. Wouldn’t it be nice if some tool already existed to do this for us? Fortunately, there is.
The tool is a library that Microsoft ships with Dynamics 365 and its full reference is Microsoft.Dynamics.AX.Frameworks.ProductConfiguration. We can use the Object Browser in Visual Studio to see the namespaces, classes and methods packed into this assembly.
Suppose we can obtain the XML document that has the configured product information. We want to find the configured product’s total price from the XML document without any user input. The key is to use the Product Configurator interface. We’ll write an X++ class that calls the Product Configurator interface and sends parameters to initialize it. Once initialized, we can add an event handler to the CalculationSummary event to find the configured product’s total price.
First, we create the interface with the XML document, which is passed into the below method as _xmlModel, and add the event handler. We then set the solver strategy and some parameters for the configurator, load some attribute values and start the configurator session:
Once the Product Configurator completes the parsing process, it will raise the CalculationSummary event. We loop through the calculation results and sum up the total price in the totalPrice variable.
Once you have these key ingredients, you can create a method to return the totalPrice variable to show the configured product’s total price without any user input. The class variables and other helper methods are shown below for completion:
For more information on importing data, contact BKD’s Microsoft Dynamics GP support center.