Product Configuration: Setting values based on system variables – example, current user ID

In this blog post we will describe how you can  set values
based on the current user ID by leveraging system-defined table constraints
together with the build-in query range methods.

 

If you are familiar with the Product Builder configurator,
you may by familiar with the User Profile
feature where you can associate a collection of default values with a given
user. Use the following description to achieve a similar behavior using the
Product Configurator.

Creating the System Table

 

The table we create for this example should look like this and have two columns, that is, one for
the User ID (uses the  UserID EDT) and one for our user-specific value (an Integer to keep it simple).

 

 

 

Once the table is created, we can add the user specific data.

 

As seen above, we have added the value 42 for the Admin
user ID. The intention is that when the table constraint is created and used in
model, the attribute, which will be bound to the UserSpecificIntegerValue
column, will be assigned the value that corresponds to the current user ID.

 

Creating the Table Constraint

Now that the System Table is created, we can create the actual table constraint. This is done by
opening the Table constraint definition
form, under Product information management -> Common -> Product configuration models.

Create a new table constraint by clicking the new button.

 

Select System defined, and enter the name of the table created previously.

 

Add a column for the user-specific integer value and choose an integer attribute type with ranges.

  

Now comes the part which gives the attribute a user-specific value. This can be accomplished by
opening the Select query (SysQuery) form and entering the range specified
below. The content of the table will be filtered to just return the records
associated with the current user ID.

 

Click OK to complete the table constraint creation, click Next in the Wizard, and then click OK again.

Using the system-defined table constraint in a Product configuration model

Having just created our system-defined table constraint, we are now ready to use it in a Product
configuration model. Below I have create a very simple model with 3 attributes:

  1. One integer attribute to hold
         the user-specific value
  2. Two boolean attributes for
         each of which I will be using the Hidden modifier with a condition
         expressing that the attribute is only to be shown if the user-specific
         value matches that of the current user. 
         The “Only Admin” attribute will be hidden if the user
         specific value is different from 42.

 

 

Similarly, I have added an attribute named “Only Dmitry”, which only will be
visible if the user log on to Dynamics AX is associated with User ID Dmitry.

 

Once the attributes have been defined, it’s time to attach the table constraint to the
model. This is done by creating a new constraint in the constraints section and
selecting Table constraint in the opened dialog.

Then select the new table constraint and associate the user-specific value attribute with
the user-specific value column, as shown below.

 

Launching the model and understanding the results

We are now ready to launch the model we created with the attached table constraint. As can be seen
below, once the model is loaded, the User Specific Value is assigned the value 42 by the configurator. The “Only
Admin” attribute is shown and the”Only Dmitry” attribute is hidden.

 

 

This example can be extended to include several other concepts like hiding subcomponents and
grouping user specific value into table constraints. An obvious use case would
be that you hide some parts of the Product configuration model from the order
takers (Susan persona). This could be engineering-specific details and the
product designer (Emil persona) would still be able to see them.

 

Furthermore, the above pattern can be used together with other of the build-in query range
methods.

 

  • currentCompany
  • currentLanguageId
  • currentUserLanguage
  • currentLegalEntity
  • currentParty

 

Note:

It you are running
on a build that has a performance fix to run the XML generation in IL, you will
need to generate IL for the SysQueryRangeUtil class.

 

I hope you find this useful 

 

 

 

PrivateProject_MyUserSpecificValuesDemo.xpo

Product Configuration – Physical data model for user selected values

A constraint-based configurator was shipped with Microsoft
Dynamics AX 2012. In this post, we will provide an overview of the data model
that is used to persist the values that you can select when you configure a
product using the constraint-based configurator.

 

 

 

 

At first glance, you will notice that there are several
tables involved. If you are not familiar with previous versions of Dynamics AX
and the Product Builder configurator, this might not surprise you. However, if
you are familiar with the Product Builder, you will know that the old
configurator persisted all user selections in one table, namely the
PBATableInstance Table. This implies that retrieving the user selected values
is not as simple as writing a select statement against a single table. In the
following, I will use a report as an example and show you how you can retrieve user
selections in tables.Building a report

The report** that we use as an example displays all the user
selected values that are related to the configurations for a given product configuration
model.

**Disclaimer:
The report is not performance optimized. The purpose of the report is solely to
illustrate traversal of the data structure.

 

In the report, each element is indented to show the
parent-child relationship between, for example, the HomeTheaterSystem root
component and the “Color” attribute. The “Color” attribute can be assigned
other values, such as “Red”, but in the data on which the report was executed
no such configuration existed.

Note: I have used the Contoso dataset.

Data requirements

The data required to build the report can be broken down
into three parts:

  1. Get the instances of the root component from a
    given product configuration model. Here we only want the instances that are
    created for product variants and not the ones that are created for configuration
    templates.
  2. Get the attributes and their user selected
    values for a component instance.
  3. Traverse the subcomponent instances recursively
    and repeat part 2.

 

Let’s take a look at how to retrieve the data requirements to
build the report. The following statements will meet the data requirements and you
can also see the table involved:

Get the instances of the root component from a product configuration model

 

 protected void
  provideDataForModel(PCProductConfigurationModel _productConfigurationModel)

{

   PCVariantConfiguration              variantConfiguration;

   PCComponentInstance                 componentInstance;

   PCComponentInstanceRootComponent    rootComponentInstance;

   PCClass                             rootComponent;

   // get all
  configurations made for the given product configuration model

   while select componentInstance

   // only get instances which belong to a variant configuration, not a configuration template

  join TableId from variantConfiguration

  where variantConfiguration.RecId == componentInstance.ProductConfiguration

  // find the
  root component instances of the selected model

  join TableId from rootComponentInstance

  where rootComponentInstance.ComponentInstance == componentInstance.RecId

  join  rootComponent

  where   rootComponent.RecId ==  rootComponentInstance.RootComponentClass

        &&      rootComponent.RecId == _productConfigurationModel.RootComponentClass

    {

        //  handle data for component

        …

    }

}

 

Get the attributes and their user selected values for a component instance

 

    PCComponentInstanceValue    componentInstanceValue;

    EcoResAttribute             attribute;

    EcoResAttributeValue        attributeValue;

    EcoResValue                 value;

    

    // get all attribute value assignments
  related to the component instance

    while select  value

        join TableId from attributeValue

        where  value.RecId == attributeValue.Value

        join TableId from componentInstanceValue

        where componentInstanceValue.RecId  == attributeValue.InstanceValue

        &&    componentInstanceValue.ComponentInstance  == _componentInstance.RecId

        join attribute

        where attribute.RecId == attributeValue.Attribute

    {

   // handle data for attribute and attribute value

    …

    }

 

The values as such are sub-typed to model their respective data type.

Traverse the subcomponent instances

 

   

    PCComponentInstance    componentInstance;

    PCComponentInstanceSubComponent  subComponentInstance;

 
    PCSubComponent  subcomponent;

    PCClass                  childComponent;

 

// get all the subcomponents that have been associated with values

while select component

        join TableId from subcomponent

        where  subcomponent.ParentComponentClass == _parentComponent.RecId

        &&    subcomponent.ChildComponentClass  == childComponent.RecId

        join TableId from subComponentInstance

        where subComponentInstance.SubComponent == subcomponent.RecId

        &&  subcomponentInstance.ParentComponentInstance == _componentInstance.RecId

        join componentInstance

        where componentInstance.RecId == subComponentInstance.ChildComponentInstance

    {

   // handle data for component

    …       

    }

 

 

Implementation of the report

 

The data in the report is hierarchical in nature because of
the relationship between components and subcomponents.

The report that we build includes the parent-child
relationship between a component and a subcomponent and it also includes the parent-child
relationships between, for example,  an
attribute and an attribute value. This data cannot be retrieved from Dynamics
AX using a single query[1]
so we will use a data provider to populate a temporary table. The table has the
following structure:



[1]
This is not completely true because in Dynamics AX 2012, each component is
brought about as a reference to the configured variant. Thus, you could
retrieve all the data and then resolve the parent/child relations once the data
is retrieved.

 

A quick explanation of why the fields are required:

  • ID : this is used because the report framework
    will not expose the RecId field of the temporary table
  • Name : this is the name, such as Color, that we choose to display for the
    element
  • Parent : this is a reference to the parent
    record ID that helps grouping the SSRS report hierarchically
  • UniquePath : this is used to distinguish the
    attributes that belong to subcomponents of the same type. The path will be
    unique since it describes the path from the root component to each element in
    the model.

 

For more information about how to build a simple
hierarchical report in SSRS, go to:

http://technet.microsoft.com/en-us/library/dd255243(v=sql.105).aspx

For details on the implementation, take a look at the
attached X++ project.

Enjoy

PrivateProject_PCSessionValues.xpo

Importing product configuration models into AX 2012 R2

Some of the new features in Product configurator for Microsoft Dynamics AX 2012 R2 required that changes were made to the schema for product configuration models. As a result, if you want to import a product configuration model that was exported from a previous version of Microsoft Dynamics AX, you must make sure that the schema adheres to the new structure.

 

This blog post describes how to transform a product configuration model that was exported to xml from Microsoft Dynamics AX 2012 so that it adheres to the new schema for Microsoft Dynamics AX 2012 R2.

 

Disclaimer:

This method of importing product configuration models is not supported. The below xslt file is provided as is. You should review the imported product configuration models to verify that they do not contain any issues.

  

Use XSL transformations to update the schema

A product configuration model is exported from Microsoft Dynamics AX 2012 as a plain xml file named model2012.xml. You can update the xml to the new schema by using XSL transformations. By running the following command from a command prompt, you can convert the XML file using the attached xslt file and the MSXSL tool.

 

msxsl “model2012.xml” “transform2012toR2.xslt” -o model2012R2.xml

 

The command simulates what would happen during a standard upgrade process, and creates new file named model2012R2.xml that has the default values for new fields. You can import this file into Microsoft Dynamics AX 2012 R2.

transform2012toR2.xslt

Table Constraint Definitions

In this blog I’ll explain the concept of table constraints as it is implemented in Constraint-based product configuration in Microsoft Dynamics AX 2012.

 

Definition

A table constraint lets you specify the valid combinations of attribute values that can be assigned when configuring a product configuration model. The structure of a table constraint consists of one or more columns and one or more rows. Each column is assigned to an attribute type that specifies the attribute values that can be combined in the rows. Each row defines a valid combination of the attribute values for the attribute type.

 

Constraint based product configuration for Microsoft Dynamics AX 2012 supports two types of table constraints:

 

  • User-defined – You can manually specify the combinations of attribute values that are valid for the product configuration model.
  • System-defined – You can specify the table in the Application Object Tree (AOT) that will define the combinations of attribute values that are valid for the product configuration model.

 

Example

The following example shows a table constraint that could be used for a television. The table constraint is described as an expression and as a table. The expression describes the attribute types and values for Color, Size, and IsLCD. The table constraint contains three columns with the valid combinations of the attribute values for each attribute type.

 

Attributes types and values written as an expression

 

IsLCD : { True, False }      

 

Color : { “Red”, “Green”, “Blue”, “Black” }     

 

Size : [ 42 .. 55 ]   

 

Table constraint

 

The Color, Size and IsLCD attribute types serve as the column headings in the table constraint definition. The rows specify the valid combinations of attribute values.

 

Column_Color = Color

 

Column_Size = Size

 

Column_IsLCD = IsLCD

 

 Column_Color

 Column_Size

 Column_IsLCD

 Red

 42

 True

 Red

 55

 True

 Green

 42

 True

 Blue

 55

 False

Written as a Boolean expression, the table would look as follows: 

 

(Color == “Red” And Size == 42 And IsLCD == True )

Or

(Color == “Red” And Size == 55 And IsLCD == True )

Or

(Color == “Green” And Size == 42 And IsLCD == True )

Or

(Color == “Blue” And Size == 55 And IsLCD == False )

 

There are some important things to note about the attribute types that are used in the example:

 

  • Color:  This attribute type includes the attribute value “Black.” However, because Black is not specified in a row it cannot be assigned. In a case like this, consider whether the table constraint or attribute type are incorrect. The two rows for the attribute value “Red” implies that if Red is assigned then Size can either be 42 or 55. This also means that the IsLCD attribute is always True because the values for Red and IsLCD is True are not combined in a row.
  • Size:  Although the attribute type is defined as an integer with an interval from 42 to 55, only the values 42 and 55 are valid attribute values because these are the only values within the interval for which a row is defined.
  • IsLCD:  If False is assigned to an attribute value that is included in the IsLCD column, then only “Blue” and 55 are valid assignments for the respective attribute values that are included in the Color and Size columns.

 

The difference between System and User defined table constraints

Although the same rules apply to both system-defined and user-defined table constraints, there are some differences in behavior. In this section I’ll elaborate on the key differences, but focus primarily on system defined table constraints.

 

User defined

User defined table constraints let you manually define the combinations of attribute values that you want to allow for a product configuration model. In Figure 1, the Table fields and Allowed combinations FastTabs of the Edit table constraint form show an example how attribute types and values are combined in a user defined table constraint.

 

Figure 1

System defined

For system defined table constraints, you select a table or view which is defined in the AOT. You then specify the relation between the columns of the table constraint and the fields that are included in the table or view in the AOT. This table or view provides the value combinations for the table constraint. You can also add a filter on the AOT table or view by adding a database query that selects rows by adding ranges to query.

 

One important thing to know about system defined table constraint is that at runtime the system changes the type definition of any attribute that is associated with a column. For example, the value for an enumerated text attribute will be replaced with the set of distinct values for the column in the AOT table. For an integer-based attribute, the ranges will be replaced with the maximum and minimum values for the column.

 

 

Figure 2

Example

The InventTable table in Microsoft Dynamics AX 2012 contains the following data in the AltItemId and BOMLevel fields.

 

 AltItemId

 BOMLevel

 LCD_42

 3

 Plasma_55

 1

 LCD_55

 7

 

In order to use the InventTable as the source of a system defined table constraint for a component in a product configuration model, the following must be set up:

 

  • Two attribute types, one of the type Text and another of the type Integer. The Text attribute type must have at least one value. The Integer attribute type must have a value range.
  • A table constraint definition, as illustrated in Figure 2. The table constraint that will reference the definition must be created for a component. The component must have attributes that match the attribute types that are referenced by the columns of the table constraint definition.

 

For a component that uses a system defined table constraint, the system replaces the following values:

  • For the attribute type of the attribute that is matched to the AltItemId column, the values are replaced with { “LCD_42”, “Plasma_55”, “LCD_55” }.
  • For the attribute type of the attribute that is matched to the BOMLevel, the range is replaced with [ 1 .. 7 ].