Walkthrough: Adding a table for customer preferences to the AX 2012 database
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
In this walkthrough you create a new table in Microsoft Dynamics AX 2012 to capture additional customer data in a retail channel. The new table is called RetailCustPreferences and it is related to the CustTable so that each customer has the new fields for marketing preferences. You modify the customer form to display and add values to the field in the new table.
Prerequisites Create the RetailCustPreferences table Add the new fields to the Customer form |
Prerequisites
These walkthroughs illustrate adding a field to a retail channel that enables customers to opt in to receive special offers by email. In this scenario, the retailer wants to indicate whether customers wish to receive email about special offers, either in an online store or in a modern POS client. The walkthroughs should be completed in the following order:
Walkthrough: Adding a table for customer preferences to the AX 2012 database
Walkthrough: Extending the CRT to add customer preference data for Retail clients
Walkthrough: Extending retail data distribution infrastructure for customer preferences
Walkthrough: Adding customer preferences to the Retail online sample store (online store only)
In the first walkthrough, you create a table to store the customer preferences. The following links provide background information about creating a new table.
Create the RetailCustPreferences table
You use the Data Dictionary in the AOT to add a new table.
To add a new table
In the Microsoft Dynamics AX client, press CTRL + D to open the development workspace.
In the AOT, expand DataDictionary, right-click the Tables node, and then click New Table.
Right-click the new table name and then click Properties.
Set the Name property to RetailCustPreferences and then press Ctrl+S to save the new table.
Expand the new RetailCustPreferences node, right-click the Fields node, click New, and then click Enum.
Specify the following properties for the new field:
Property
Value
Name
EmailOptIn
Label
Email Opt In
EnumType
NoYes
Press Ctrl+S to save your changes.
To create the relation on the new table
In the AOT, expand the Data Dictionary node, expand the Tables node and then expand the RetailCustPreferences node.
Right-click Relations and then click New Relation.
Right-click the new relation and then click Properties.
Set the values for the properties as shown in the following table.
Property
Value
Name
CustTable
Table
CustTable
Validate
Yes
EntityRelationshipRole
blank
RelatedTableCardinality
ExactlyOne
Cardinality
ZeroOne
RelationshipType
Composition
UseDefaultRoleNames
Yes
RelatedTableRole
blank
Role
blank
EDTRelation
No
Right-click the new relation, select New, click ForeignKey, and then click PrimaryKey based.
Notice the CustTable field is added for the RetailCustPreferences table in the Fields node, and the relation is added in the Relations node under CustTable.
Right-click the new relation under CustTable and then click Properties.
Set the SourceEDT property to CustAccount.
Under the Fields node, right-click CustTable and then click Properties.
Set the properties as shown in the following table.
Property
Value
Name
AccountNum
ExtendedDataType
CustAccount
Right-click RetailCustPreferences and then click Save.
Right-click RetailCustPreferences and then click Sychronize to apply your changes to the database.
Right-click RetailCustPreferences and then click Compile.
To view the contents of the table and add data, you can right-click ISVCustomerMarketingPreferences in the Tables node, click Add-Ins, and then click Table Browser.
Close the developer workspace and any Microsoft Dynamics AX clients.
Add the new fields to the Customer form
Adding the fields from the new table to the Customer form enables adding data for a test customer by using the Microsoft Dynamics AX client. You add the new table to the Datasource node of the CustTable form.
To add a field to the Customer form
Open the Microsoft Dynamics AX developer workspace.
In the AOT, expand the Forms node and then expand the CustTable node.
Right-click Data Sources and then click New Data Source.
Right-click the new data source and then click Properties.
Set the properties as shown in the following table.
Property
Value
Name
RetailCustPreferences
Table
RetailCustPreferences
Index
blank
CounterField
blank
AllowCheck
Yes
AllowEdit
Yes
AllowCreate
Yes
AllowDelete
Yes
StartPosition
First
AutoSearch
Yes
AutoNotify
Yes
AutoQuery
Yes
CrossCompanyAutoQuery
No
OnlyFetchActive
No
JoinSource
CustTable
LinkType
OuterJoin
DelayActive
Yes
InsertAtEnd
Yes
InsertIfEmpty
Yes
Right-click CustTable in the Forms node and then click Save.
Expand the Designs node, the Design node, the Tab:Tab node, and then the TabPage:TabPageDetails node.
Expand the Tab:TabHeader node to view the FastTab categories.
Right-click the TabPage:Retail node, select New Control, and then click Group.
Set the Name property for the new group to CustomerPreference and set the Caption property to Customer preferences.
Right-click the Group:CustomerPreference node, select New Control and then click CheckBox. Set the following properties.
Property
Value
Name
RetailCustomerPreferences _EmailOptIn
DataSource
RetailCustPreferences
DataField
EmailOptIn
Label
Email Opt In
Right-click CustTable in the Forms node, click Save, and then click Compile. You can disregard the Best practices messages.
Right-click CustTable and then click Open to view the form. Click Edit on the Action pane.
Click Retail to open the Retail FastTab.
Now, we must write code to populate the Customer account.
In the AOT, open the Forms node and navigate to the CustTable form.
Right-click CustTable, click View Code.
Click CustTable:validateWrite. Add the following line of code to the block before the ret = super(); statement: retailCustPreferences.AccountNum = custTable.AccountNum;.
The following example shows the code block with the new statement.
whsCustTable.AccountNum = custTable.AccountNum; if (isConfigurationkeyEnabled(configurationKeyNum(Retail))) { retailCustTable.AccountNum = custTable.AccountNum; retailCustPreferences.AccountNum = custTable.AccountNum; } ret = super();
Click CustTable:write. Add the following line of code to the block before the first ttsbegin; statement: retailCustPreferences.AccountNum = custTable.AccountNum;.
The following example shows the code block with the new statement.
if (isConfigurationkeyEnabled(configurationKeyNum(Retail))) { retailCustTable.AccountNum = custTable.AccountNum; retailCustPreferences.AccountNum = custTable.AccountNum; } ttsbegin;
Press CTRL+S to save your changes. Close the Code Editor window.
Right-click the CustTable form and then click Compile.
Restart the AOS.
Right-click the CustTable form and then click Open to view the form. If you have test data loaded, the data shown is for the first customer. Click Edit and then open the Retail FastTab. Use the Email Opt In check box to set the value for a few customers.