AX2012 Core Concept WP_PriceDiscPolicies_1

Microsoft Dynamics AX 2012
®
Trade agreement evaluation
policies in Microsoft
Dynamics AX 2012
Implementation Considerations
TAE-Policies are an out-of-box feature of Microsoft Dynamics AX
2012 that prevents unintentional overwriting of prices and
discounts that are manually entered, or that originate from
sources other than the built-in trade agreement system. This
document explains the architecture, and also provides hints for
extending and debugging TAE-Policies. It assumes familiarity
with the concepts of sales orders, sales quotations, and
purchase orders, how they are created, and how they interact
with trade agreements. Conceptual knowledge of the Microsoft
Dynamics AX 2012 agreement feature will also be useful.
March 2012
www.microsoft.com/dynamics/ax
Lars David Jørgensen, Software Development Engineer
Send suggestions and comments about this document to
adocs@microsoft.com. Please include the title with your
feedback.
CCAX2012IC3001
Table of Contents
TAE-Policies overview ................................................................................. 3
Scenarios that support TAE-Policies with Microsoft Dynamics AX ............... 3
Sources – What are they? ...................................................................................................... 3
Trade agreements.............................................................................................................. 4
Manual input ..................................................................................................................... 4
System sources ................................................................................................................. 4
Sales and purchase agreements .......................................................................................... 4
TAE-Policies – More details ..................................................................................................... 4
Dynamic policies ................................................................................................................ 5
Fixed policies .................................................................................................................... 5
Summary.......................................................................................................................... 6
Manual TAE-Policy applied to a document header or line record .................................................. 6
Example: Manually overwrite the unit price ........................................................................... 6
System TAE-Policy applied to a document header and line ......................................................... 7
Example: System policy originating from a sales quotation ..................................................... 7
Manual and system TAE-Policies applied to the same document header and line ........................... 8
Example: Manually overwrite system policies originating from a sales quotation ........................ 8
Architecture of TAE-Policies in Microsoft Dynamics AX ............................. 12
Some design highlights .........................................................................................................12
ER diagram .........................................................................................................................14
Class diagrams ....................................................................................................................15
Glossary of terms ...................................................................................... 17
Appendix ................................................................................................... 20
Sequence diagrams ..............................................................................................................20
Class diagrams ....................................................................................................................23
Showcase – Extending TAE-Policies ........................................................................................24
Installation and upgrade .......................................................................................................26
Performance considerations...................................................................................................26
Debugging hints ..................................................................................................................26
2
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
TAE-Policies overview
Purchase order lines, sales quotation lines, and sales order lines all include fields (trade agreement
result fields: see the Glossary of terms section) that can be:

Entered by trade agreements.

Entered by manual input.

Set from external sources, such as sales quotations, project quotations, purchase requisitions,
requests for quotation (RFQs), agreements, projects, Application Integration Framework (AIF),
and Enterprise Portal for Microsoft Dynamics® AX (EP).
The lines also include the Net amount field, which can be either calculated based on trade
agreements or entered from one of the external sources.
The TAE-Policies feature prevents Microsoft Dynamics AX from accidentally evaluating the trade
agreements and overwriting fields populated by manual input or a system source (see the Glossary of
terms section).
Note: The TAE-Policies feature is used only in the context of price and discount fields on sales
quotations, sales orders, and purchase orders. It is related neither to the policy framework used for
designing and enforcing business rules, nor to the framework that creates extensible data security,
both of which are being introduced in Microsoft Dynamics AX 2012.
Also, the TAE-Policies feature is not implemented in intercompany scenarios.
Scenarios that support TAE-Policies with Microsoft
Dynamics AX
This section describes some core concepts and some of the most common scenarios in which TAEPolicies are implemented within Microsoft Dynamics AX.
For sales orders, purchase orders, and sales quotations, two main steps are performed:

When a trade agreement result field is populated from a system source or updated manually, a
TAE-Policy is created, and a reference to the TAE-Policy is added to the document.
Changing a trade agreement condition field triggers a recalculation of the trade agreement result
fields. The user is prompted for permission to overwrite the field values entered in this step.

When a line amount field is overwritten manually, and changes to a trade agreement condition
trigger a recalculation of the trade agreement result fields, the user is prompted for permission to
change the manually entered value.
Whether the different types of field entries (manually entered or entered from different system
sources) should be subject to TAE-Policies is controlled by new sets of customer and vendor
parameters.
Sources – What are they?
The trade agreement result fields are populated from different sources, depending on the scenario. In
this context, we divide the sources into several groups, some of which can be guarded by policies.
3
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Trade agreements
This is the legacy price discount setup that has been present in Microsoft Dynamics AX since version 1
and is considered the default source in the default scenario: the user creates or updates a document
directly from the UI.
In this scenario, no TAE-Policies are applied.
Manual input
The user enters a value in one of the trade agreement result fields.
A manual-type TAE-Policy is applied to prevent the user input from being overwritten by the trade
agreements.
System sources
Documents are created or updated by means other than the default scenario—that is, they are
imported via AIF or copied from other documents.
A system-type TAE-Policy is applied to prevent one or more trade agreement result fields from being
overwritten by the trade agreements.
For the complete list of system sources, see the Glossary of terms section.
Sales and purchase agreements
The agreement feature that is replacing blanket orders in Microsoft Dynamics AX 2012 can be
considered a source for prices and discounts, along with the legacy trade agreement feature.
Depending on the specific agreement configuration, a subset of the price and discount values that
previously came from the trade agreement setup now comes from agreements.
The agreement feature serves as a source in two ways:

As long as a document is linked to an agreement, the agreement is considered a system source.
To control the mix of agreements and trade agreements, a set of fixed TAE-Policies is
implemented in the price discount policy feature. The purpose is to prevent price and discount
values that originate from agreements from being overwritten by trade agreements. More details
on the fixed TAE-Policies are provided later in this document.

When a document is unlinked from an agreement, prices and discounts that originate from the
agreement can be preserved. In that scenario, the agreement is considered a system source, and
a policy is applied accordingly.
TAE-Policies – More details
As has been mentioned, TAE-Policies come in two “flavors.” One is dynamic, and includes the manual
and system types, and the other is static, and includes the fixed type.
4
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Dynamic policies
A dynamic TAE-Policy is represented by a record in the PriceDiscChangePolicy table that is related to
one or more records in the PriceDiscPolicyFields table.
Document header
Document line
DataAreaId
<....>Id
DataAreaId
InventTransId
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
<....>Id (FK,AK1)
LineNum (AK1)
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
PriceDiscChangePolicy
RecId
SearchKey (AK1)
PriceDiscPolicyFields
RecId
FieldId (AK1)
ChangePolicy (FK,AK1)
Depending on the source, the ID of the record is populated in either the ManualEntryChangepolicy
field or the SystemlEntryChangepolicy field of the document. In the latter scenario, the
SystemEntrySource field is also is populated to identify the type of system source. The following are
some characteristics of dynamic policies:

The application is parameter-controlled.

The policies are created on the fly.

The policies are immutable, and they are reused.

One document can have both a manual policy and a system policy applied at the same time, but a
specific field can only be controlled by only one type of policy at a time. For more details on
combined policies, see the Manual and system TAE-Policies applied to the same document header
and line section.
More implementation details are provided later in this document.
Fixed policies
Policies of this type are hard-coded in the PriceDiscPolicyFixed class. They are sets of rules that are
applied to documents, depending on document attributes. In Microsoft Dynamics AX 2012 RTM, fixed
policies are used in two scenarios:


Document lines are attached to agreements. This scenario has two sets of rules:

For quantity-based agreements, the Price, Line discount, Line discount pct., and Price
unit fields are controlled by fixed policies.

For volume-based agreements, the Line discount pct. field is controlled by a fixed policy.
On category-based document lines, the Price and Markup fields are controlled by fixed policies.
5
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Summary
In summary, the TAE-Policies feature implements two different sets of TAE-Policies:

The parameter-controlled dynamic type (manual and system policies) – These policies are
attached and detached on the fly, based on user actions and dialog boxes.

The hard-coded static type (fixed policies) – These policies control how agreements and trade
agreements interact.
Manual TAE-Policy applied to a document header or line record
A manual policy is applied to a document when the user overwrites one or more of the trade
agreement result fields.
Example: Manually overwrite the unit price
For this example, a document line has a stocked product, a quantity, and a unit price. No sales or
purchase agreement is attached.
The unit price is then changed, and the flow illustrated in Figure 1 is executed. In this case, a policy
indicating that the unit price was changed is applied to the document line.
Fig .1 : M an u ally overw rite a trade agreem en t resu lt field - sim plified .
N ew record is created in
the PriceD iscChangePolicy
table.
N ew record is created in the
PriceD iscChangePolicyFields
table.
No
D oes a
reuseable policy
exists?
The docum ent is
updated w ith the
policy ID
Yes
The policy is selected in
the PriceD iscChangePolicy
table.
Next, the quantity is changed, triggering a recalculation of the trade agreement fields. The flow
illustrated in Figure 2 is executed, and three outcomes are possible:

OK is clicked:
1. The unit price is recalculated in accordance with the trade agreement setup.
2. The TAE-Policy is removed from the record.

The Unit price check box is cleared, and OK is clicked:
1. The manually entered unit price is kept.
2. The TAE-Policy remains on the record.

Cancel is clicked:
1. Update of the record is canceled, rolling back the quantity change.
2. The TAE-Policy remains on the record.
6
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Even though the appearance of the dialog box differs in different scenarios, the flow and outcomes are
similar.
Fig.2: Recalculation of the trade agreement result fields - simplified.
The price discount
dialog is launched
Yes
Is a policy
applied to the
document?
The map field ID corresponding
with the unit price is removed Yes
from the policy.
The user leaves
the check mark.
No
No
Is the map field
ID of the unit
price in the
policy?
Yes
No
The unit price is
updated
Update of the unit
price is blocked
System TAE-Policy applied to a document header and line
A system policy is applied to a document when it is created from sources other than manual input by a
user.
Example: System policy originating from a sales quotation
For this example, a sales quotation has one or more lines. The line items are all stocked products, and
no sales agreements are involved.
7
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
The confirmation process is started to create a sales order based on the sales quotation. As part of
that process, the price discount policy functionality is called to apply system policies to the new sales
order, as illustrated in Figure 3.
F ig .3 : S y s te m p o lic y o rig in a tin g fro m a s a le s q u o ta tio n
C re a tio n o f th e
d o c u m e n t h e a d e r re c o rd
N e w re c o rd c re a te d in
P ric e D isc C h a n g e P o lic y F ie ld s
N e w re c o rd c re a te d in
P ric e D isc C h a n g e P o lic y
No
T h e so u rc e ty p e a n d
docum ent header
p o lic y is d e te rm in e d
Does a
re u se a b le p o lic y
e x ists ?
Yes
T h e p o lic y is se le c te d in
P ric e D isc C h a n g e P o lic y
T h e so u rc e ty p e a n d
d o c u m e n t lin e
p o lic y is d e te rm in e d
Yes:
C re a tio n o f th e
d o c u m e n t lin e re c o rd (s)
A t th e la te st a fte r first d o c u m e n t lin e
is p ro c e sse d , th is is tru e fo r re m a in in g lin e s .
T h e d o c u m e n t is
u p d a te d w ith th e
p o lic y ID
A re
d o c u m e n t lin e
re c o rd s p e n d in g
c re a tio n ?
No
Manual and system TAE-Policies applied to the same document
header and line
As has been mentioned, a document can be controlled or protected by both a manual policy and a
system policy at the same time. However, a particular field can be subject to control by only one
policy at a time. Nevertheless, the type of policy that controls a particular field can shift from manual
to system, and from system to manual.
Example: Manually overwrite system policies originating from a sales quotation
For this example, a sales order is created based on a sales quotation, as described in the previous
example. Both the header and the line records have system policies applied that indicate the origin.
8
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Triggering a recalculation of the trade agreement opens a dialog box, and the steps that are executed
are similar to the steps in Figure 2.
First, we describe the appearance of the dialog box when only the system policies are applied.
On the document header, the calculation of multiline discounts is started, and the following dialog box
appears.
This dialog box indicates that multiline discounts come from the sales quotation.
As has been mentioned, we can accept or cancel the dialog box. For now, assume that Cancel is
clicked.
Still on the document header, the calculation of the total discount is started, and the following dialog
box appears.
This dialog box indicates that the total discount comes from the sales quotation.
Again, assume that Cancel is clicked.
9
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Now one of the trade condition fields on the document line is changed, and the following dialog box
appears.
This dialog box indicates that a system policy of type SalesQuotation that includes all five trade
agreement result fields for the document line exists on the document line.
Assume that Cancel is clicked. In this case, the Discount and Discount percent fields are
overwritten.
For each overwritten field, the flow illustrated in Figure 4 is executed.
10
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
F ig 4 : M a n u a lly o v e r w r ite a tr a d e a g r e e m e n t r e s u lt fie ld .
( M o r e d e ta ile d )
Is th e fie ld ID
su b je c t to a
fix e d p o lic y o r
a lre a d y in c lu d e d
in a m a n u a l
p o lic y a p p lie d to
th e d o c u m e n t?
Yes
No
Is a m a n u a l
p o lic y a lre a d y
a p p lie d to th e
d o c u m e n t?
No
Yes
A n e w m a n u a l p o lic y
m e rg in g th e n e w fie ld ID
a n d th e e x istin g p o lic y ,
sh o u ld b e a p p lie d .
A n e w m a n u a l p o lic y w ith
o n ly th e n e w fie ld ID
sh o u ld sh o u ld b e a p p lie d .
Does a
re u se a b le p o lic y
e x ists?
Yes
No
A n e w re c o rd is c re a te d in th e
P ric e D isc C h a n g e P o lic y ta b le .
T h e p o lic y is se le c te d in th e
P ric e D isc C h a n g e P o lic y ta b le
O n e o r m o re n e w re c o rd s a re c re a te d
in th e P ric e D isc C h a n g e P o lic y F ie ld s ta b le .
A p p ly in g a
m anual or
sy ste m p o lic y ?
S y ste m
T h e d o c u m e n t fie ld
” S y ste m E n try C h a n g e P o lic y ”
is u p d a te d w ith t th e p o lic y ID a n d
th e ” S y ste m E n try S o u rc e ” fie ld is
u p d a te d w ith th e sy ste m so u rc e
in q u e stio n .
M anual
T h e d o c u m e n t fie ld
” M a n u a lE n try C h a n g e P o lic y ”
is u p d a te d w ith t th e p o lic y ID
Is a sy ste m
p o lic y
a p p lie d to th e
d o c u m e n t?
No
Yes
No
Is th e fie ld ID
p a rt o f th e
e x istin g sy ste m
p o lic y ?
A n e w sy ste m p o lic y
w ith o u t th e fie ld ID sh o u ld
re p la c e th e e x istin g o n e .
Yes
11
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Again, one of the trade condition fields on the document line is changed, and the following dialog box
appears.
Now the dialog box indicates that both a manual policy and a system policy are applied to the
document line.
Manual changes to the price discount result fields for the document header follow the same pattern:
fields are “moved” from the system policies to the manual policies.
Architecture of TAE-Policies in Microsoft Dynamics AX
Some design highlights
The following information supports the diagrams in this section:

The implementation can be seen as divided into two major parts: the core functionality common to
all documents and the document-specific integration.
Whereas the integration part is tailored to the specific document scenarios, the core part consists
of three subsystems of functionality and several common supporting elements.
The subsystems are as follows:

Make policy – Enables a given trade agreement result field to be included in a price discount
policy, or if no price discount policy exists, enables a new one to be created.

Prompt user – Enables a dialog box to be opened, providing the user with field-level
information about applied policies and also letting the user decide whether each field should
continue to be subject to policy control.

Check policy – For a given table, record, or field, answers the following question: “Is this
field blocked by a policy?”
The subsystems are marked with different colors in the core functionality class diagram.
12
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012

A TAE-Policy is a list of table field IDs.
In the database, a TAE-Policy is stored as one record in the PriceDiscChangePolicy table, and each
table field ID belonging to a TAE-Policy is stored as a separate record in the PriceDiscPolicyFields
table.
Both tables, PriceDiscChangePolicy and PriceDiscPolicyFields, are immutable: after records have
been created, they are never updated or deleted.

When records are created in the PriceDiscPolicyFields table, the field IDs representing the policy
are converted to the corresponding field IDs from the PriceDiscResultFields table map.
When policy field IDs are retrieved from the PriceDiscPolicyFields table, they are converted back to
the appropriate table field IDs.
13
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
ER diagram
SalesLine
DataAreaId
InventTransId
SalesTable
DataAreaId
SalesId
LineNum (AK1)
SalesId (FK,AK1)
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
PurchTable
SalesQuotationTable
DataAreaId
PurchId
DataAreaId
QuotationId
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
PriceDiscChangePolicy
RecId
SearchKey (AK1)
PurchLine
SalesQuotationLine
DataAreaId
InventTransId
DataAreaId
InventTransId
PurchId (FK,AK1)
LineNum (AK1)
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
LineNum (AK1)
QuotationId (FK,AK1)
SystemEntryChangePolicy (O) (FK)
ManualEntryChangePolicy (O) (FK)
SystemEntrySource (O)
More....
PriceDiscPolicyFields
RecId
FieldId (AK1)
ChangePolicy (FK,AK1)
New table: PriceDiscChangePolicy
3 new enum types
PriecDiscSalesPromptSystemSource
AIF
SalesAgreement
CopyFromSalesOrder
CopyfromSalesQuotation
Project
ProjetQuotation
SalesQuotation
ManualEntry
ProductConfig
PriceDiscPurchasePromptSystemSource
AIF
PurchaseAgreement
CopyFromPurchaseOrder
Project
PurchaseReq
RequestForQuote
ManualEntry
ProductConfig
PriceDiscSalesPolicyParameters
PriceDiscSystemSource
None
CopyFromSalesOrder
CopyFromSalesQuotation
Project
SalesQuotation
CopyFromPurchaseOrder
RequestForQuote
PurchaseReq
ManualEntry
Agreement
Aif
ProductConfig
Id
PriecDiscSalesPromptSystemSource (AK1)
PriceDiscPurchPolicyParameters
Id
PriceDiscPurchasePromptSystemSource (AK1)
14
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Class diagrams
As has been mentioned, the core part of the implementation consists of three subsystems and several
supporting elements. The following diagram is color-coded to group the elements by subsystem, and
the integration with the document-specific integration is also shown.
Class diagram: Core functionality
Subsystem main elements
Make policy
Prompt user
Check policy
«subsystem»
Document specific integration
«table»
PriceDiscChangePoliciesTmp
«Class»
PriceDiscPolicyCheckPolicy
«Class»
PriceDiscPolicyFixed
«table»
PriceDiscPurchPolicyParameters
«Class»
PriceDiscPolicyMakePolicy
«TableMap»
PriceDiscResultFields
«table»
PriceDiscSalesPolicyParameters
«Class»
PriceDiscPolicyFieldMappingCache
«table»
SRMParameters
«Class»
PriceDiscPolicyFindOrCreate
«table»
CustParameters
«table»
PriceDiscChangePolicy
«table»
PriceDiscPolicyFields
«Class»
Runbase
«Class»
PriceDiscPolicyDialog
15
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
As has been mentioned, the document-specific integration part of the implementation is tailored to
each document. The following diagram shows the purchase order part. The diagrams covering sales
orders and sales quotations are located in the appendix of this document.
Class diagram: Document specific integration - purchase orders.
«TableMap»
PriceDiscHeading
+updateFinalDisc() : bool
+updateMultiLineDisc()
«subsystem»
Core functionallity
«TableMap»
SalesPurchLine
+calcLineAmountForced() : long
+setPriceAgreement()
+setPriceDiscMarkup()
+setPriceDiscPriceUnit()
«Class»
PurchCopying
#setPriceDiscHeaderChangePolicy()
#setPriceDiscLineChangePolicy()
«Class»
PurchAutoCreate_RFQ
+createPurchTable()
+createPurchLine()
«Class»
PurchAutoCreate_PurchReq
+createPurchTable()
+createPurchLine()
«Class»
PurchAutoCreate_SalesProjectItemReq
+endUpdate()
+createPurchLine()
«Table»
PurchTable
+setPriceDiscChangePolicy()
+setPriceDiscChangePolicyMultiLine()
+modifiedField()
-unlinkAgreement()
«Table»
PurchLine
+setPriceDiscChangePolicy()
+runPriceDiscPolicyDialog() : bool
+calcLineAmountForcedInteraction() : long
+unLinkAgreementLine()
+modifiedField()
«Class»
EPPurchCOR
+corReceive() : bool
«Class»
PCSourceDocumentLineUtility
#updatePurchaseLineDetails()
«Class»
PurchLineType
+validateField() : bool
+validateModifyInventDim() : bool
+purchQtyAllowEdit() : bool
+setPriceDiscChangePolicyMultiLine()
16
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Glossary of terms
Term
Definition
Trade agreements
The legacy Microsoft Dynamics AX price and discount feature used to set
up price and discount rules for specific customers and products, groups
of customers and products, or all customers and products.
Agreements
The new Microsoft Dynamics AX 2012 feature that replaces the legacy
blanket order feature.
Trade agreement condition field
A field for which the value can be used as a requirement for a trade
agreement rule before the trade agreement can be applied.
The trade agreement conditions are as follows:
Trade agreement result field

Item number

Configuration

Size

Color

Site

Warehouse

Batch number

Serial number

Quantity

Unit
A field that can be directly set by trade agreements.
Location
Field
Document header > Price/Discount tab
Total discount %
Document line details > Price/Discount tab
Unit price
Discount
Disc. pct.
Multiline discount
Multiline discount %
Markup
These fields can all be found in the Purchase order details, Sales
quotation details, and Sales order details forms.
17
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Term
Definition
System source
When sales orders, sales quotations, and purchase orders are not created
from the details forms, their origination is considered a system source.
Manual-type TAE-Policy
System source
Description
PurchaseAgreement
A purchase order line is attached to a
purchase agreement.
CopyFromPurchaseOrder
A purchase order line is copied from
another purchase order line.
PurchaseReq
A purchase order is created based on a
purchase requisition.
RequestForQuote
A purchase order is created based on a
request for quotation.
SalesAgreement
A sales order line is attached to a sales
agreement.
CopyFromSalesOrder
A sales order line is copied from another
sales order line.
CopyfromSalesQuotation
A sales order line is copied from a sales
quotation line.
ProjectQuotation
A sales order is created based on a
project quotation.
SalesQuotation
A sales order is created based on a sales
quotation.
AIF
A document is created by importing an
XML file.
Project
A sales order is created based on a
project.
Product configurator
A sales price or purchase price is
generated by the product configurator.
A TAE-Policy that is created based on a manual update of a trade
agreement result field.
Example: On a sales line, the user has overwritten the default sales
price.
System-type TAE-Policy
A TAE-Policy that is created based on entries from external sources.
Example: A sales line was created by a sales quotation, and the sales
price was “inherited” from a sales quotation line.
For Microsoft Dynamics AX 2012 RTM, all system policy types for the
document header are the same, whereas system policy types for the
document lines come in different “flavors.”
The latter types are coded in
Classes\PriceDiscPolicyFindOrCreate\systemLinePolicyFields.
Fixed-type TAE-Policy
A hard-coded TAE-Policy that is used to control the mixture of prices and
discounts originating from agreements and trade agreements.
Document
In this context, a sales quotation, sales order, or purchase order.
Document header
A record in the SalesQuotationTable, SalesTable, or PurchTable table.
Document line
A record in the SalesQuotationLine, SalesLine, or PurchLine table.
18
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Term
Definition
Core functionality
The parts of the implementation that are common to all documents. For
more details, see the Some design highlights section.
Document-specific integration
Integration points in the legacy code. For more details, see the Some
design highlights section.
19
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Appendix
Sequence diagrams
Creation and application of a policy – simplified
«Table»
Document
«TableMap»
PriceDiscResultFields
«Class»
PriceDiscPolicyMakePolicy
«Class»
PriceDiscPolicyFindOrCreate
createPriceDiscChangePolicy(...)
makePolicy(....)
run()
Creation of a manual
or system type policy
is triggered.
findOrCreateChangePolicy(...)
changePolicyId
update()
update()
20
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
«subsystem»
Find or create policy
Launch of the price discount dialog - simplified.
«Table»
Document
«Class»
priceDiscPolicyDialog
(extends RunBase)
«TableMap»
PriceDiscResultFields
validateField(...)
runPriceDiscPolicyDialog(...)
runPriceDiscPolicyDialog(...)
runPolicyDialog()
prompt()
getFromDialog()
updatePolicy(...)
findOrCreateChangePolicy(...)
changePolicyId
«subsystem»
Find or create policy
21
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Subsystem: Find or create policy - simplified
«Class»
PriceDiscPolicyFindOrCreate
«Table»
PriceDiscChangePolicy
findOrCreateChangePolicy(...)
findSearchKey(...)
create(...)
insert()
insert()
changePolicyId
If no existing policy was found in the previous call,
a new one is created by calling create(..).
22
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
«Table»
PriceDiscPolicyFields
Class diagrams
Class diagram: Document specific integration - sales order.
«TableMap»
PriceDiscHeading
+updateFinalDisc() : bool
+updateMultiLineDisc()
«subsystem»
Core functionallity
«TableMap»
SalesPurchLine
«table»
SalesTable
+calcLineAmountForced() : long
+setPriceAgreement()
+setPriceDiscMarkup()
+setPriceDiscPriceUnit()
+setPriceDiscChangePolicy()
+setPriceDiscChangePolicyMultiLine()
+modifiedField()
-unlinkAgreement()
«Class»
SalesCopying
«table»
SalesLine
#setPriceDiscHeaderChangePolicy()
#setPriceDiscLineChangePolicy()
«Class»
AxdSalesOrder
#postSalesLineUpdate()
+processingRecord()
+setPriceDiscChangePolicy()
+runPriceDiscPolicyDialog() : bool
+calcLineAmountForcedInteraction() : long
+unLinkAgreementLine()
+modifiedField()
SalesLineType_Project
«Class»
SalesAutoCreate_ReleaseOrder
+insert()
«Class»
PCSourceDocumentLineUtility
+createSalesLine()
+createSalesTable()
#updateSalesLineDetails()
«Class»
SalesLineType
+validateField() : bool
+validateModifyInventDim() : bool
+salesQtyAllowEdit() : bool
+setPriceDiscChangePolicyMultiLine()
23
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Class diagram: Document specific integration - sales quotation.
«TableMap»
PriceDiscHeading
+updateFinalDisc() : bool
+updateMultiLineDisc()
«TableMap»
SalesPurchLine
+calcLineAmountForced() : long
+setPriceAgreement()
+setPriceDiscMarkup()
+setPriceDiscPriceUnit()
«subsystem»
Core functionallity
«table»
SalesQuotationTable
+setPriceDiscChangePolicy()
+setPriceDiscChangePolicyMultiLine()
+modifiedField()
«Class»
SalesQuotationCopying
«table»
SalesQuotationLine
#setPriceDiscHeaderChangePolicy()
#setPriceDiscLineChangePolicy()
+setPriceDiscChangePolicy()
+runPriceDiscPolicyDialog() : bool
+modifiedField()
«Class»
AxdSalesQuotation
«Class»
PCSourceDocumentLineUtility
+processingRecord()
#updateSalesQuotationLineDetails()
«Class»
SalesQuotationLineType
+validateField() : bool
+validateModifyInventDim() : bool
+setPriceDiscChangePolicyMultiLine()
Showcase – Extending TAE-Policies
Adding another system source to be policy-controlled requires only a few changes. The following
walkthrough shows how the product configurator was added as another system source.
First, the new source should be named and parameterized by adding new outcomes to the three policy
enumerations.
DataDictionary/Base Enums/PriceDiscPurchasePromptSystemSource
#ProductConfig
PROPERTIES
Name
Label
EnumValue
#ProductConfig
#@SYS344213
#7
ENDPROPERTIES
24
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
DataDictionary/Base Enums/PriceDiscSalesPromptSystemSource
#ProductConfig
PROPERTIES
Name
Label
EnumValue
#ProductConfig
#@SYS344213
#8
ENDPROPERTIES
DataDictionary/Base Enums/PriceDiscSystemSource
#ProductConfig
PROPERTIES
Name
Label
#ProductConfig
#@SYS344213
EnumValue
ENDPROPERTIES
#11
Next, the policy classes should implement the required parameter checks and the definition of which
fields are controlled for the new source. For the product configurator implementation in this example,
only the price should be controlled, because discounts are coming from the trade agreements.
Classes/PriceDiscFindORCreate/systemLinePolicyFields
.....
case PriceDiscSystemSource::ProductConfig :
ret += [fieldNum(PriceDiscResultFields, Price)];
break;
.....
Classes/PriceDiscPolicyMakePolicy checkPolicyParmSetup
Starting at line 52:
.....
case PriceDiscSystemSource::ProductConfig
ret =
PriceDiscSalesPolicyParameters::isSourceEnabled(PriceDiscSalesPromptSystemSource::ProductConfig);
break;
.....
Starting at line 94:
.....
case PriceDiscSystemSource::ProductConfig :
ret =
PriceDiscPurchPolicyParameters::isSourceEnabled(PriceDiscPurchasePromptSystemSource::ProductConfi
g);
break;
.....
Finally, a call to the <document>.setPriceDiscChangePolicy(…) method should be made at the
point where the new source is creating or updating the document. For the product configurator, this
happens in the PCSourceDocumentLineUtility class when the price is transferred.
Classes/ PCSourceDocumentLineUtility /updateSalesLineDetails
.....
_salesLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ProductConfig);
.....
25
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Classes/ PCSourceDocumentLineUtility /updatePurchaseLineDetails
.....
_salesQuotationLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ProductConfig);
.....
Classes/ PCSourceDocumentLineUtility /updateSalesQuotationLineDetails
.....
_purchaseLine.setPriceDiscChangePolicy(PriceDiscSystemSource::ProductConfig);
.....
Installation and upgrade
By default, all TAE-Policy parameters are enabled.
For new installations, this is done along with the default generation of vendor and customer
parameters.
In upgrade scenarios, it is done as part of the upgrade in the following locations:

\Classes\ReleaseUpdateDB60_Cust\initiatePriceDiscPolicyParameter

\Classes\ReleaseUpdateDB60_Vend\initPriceDiscPolicyParameter
Performance considerations
Obviously, the TAE-Policy feature has the potential to affect performance, and several design decisions
were made with that in mind:

The affected document tables are denormalized by adding the policy columns directly to the
document tables.

With regard to the PriceDiscChangePolicy and PriceDiscPolicyFields tables:

Caching of the entire table is enabled.

The tables are immutable. After records are created, they are never updated or deleted,
because they are reused across all documents and legal entities.

The number of possible records is finite and kept at a minimum by storing the field IDs of the
PriceDiscResultFields table map instead of the document table field IDs.

The mapping of the document field IDs and the PriceDiscResultFields field IDs is globally
cached in the PriceDiscPolicyFieldMappingCache class.
Debugging hints
As was mentioned in the Some design highlights section, the implementation is divided into two major
logical parts: the new core elements and the document-specific integration points.
The document-specific part is detailed in the Class diagrams section, where all new and changed
methods are included.
As has been mentioned, the core element part consists of three subsystems, and debugging hints for
each are provided here.

The make policy subsystem creates policies and applies them to documents.
Placing a break point in the PriceDiscResultFields.createPriceDiscChangePolicy() table map
method is a good starting point for debugging sessions, because all documents call that method.
26
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012

The prompt user subsystem handles the user dialog box.
Placing a break point in the PriceDiscResultFields.runPriceDiscPolicyDialog() table map
method is once again a good starting point for debugging sessions, because all documents call
that method.

The get policy subsystem determines whether a specific field is blocked.
Debug by placing a break point in the \Classes\PriceDiscPolicyCheckPolicy\mustUpdateField area,
because proceeding from here, the debugger will step through both the dynamic and fixed
policies.
27
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012
Microsoft Dynamics is a line of integrated, adaptable business management solutions that enables you and your
people to make business decisions with greater confidence. Microsoft Dynamics works like and with familiar
Microsoft software, automating and streamlining financial, customer relationship and supply chain processes in a
way that helps you drive business success.
U.S. and Canada Toll Free 1-888-477-7989
Worldwide +1-701-281-6500
www.microsoft.com/dynamics
This document is provided “as-is.” Information and views expressed in this document, including URL and other Internet Web site
references, may change without notice. You bear the risk of using it.
Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or
should be inferred.
This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and
use this document for your internal, reference purposes. You may modify this document for your internal, reference purposes.
© 2012 Microsoft Corporation. All rights reserved.
Microsoft, Microsoft Dynamics, and the Microsoft Dynamics logo are trademarks of the Microsoft group of companies.
All other trademarks are property of their respective owners.
28
TRADE AGREEMENT EVALUATION POLICIES IN MICROSOFT DYNAMICS AX 2012