Sunday, February 12, 2012

Dynamics AX 2012 Excel Add-in - Customer transactions import

Microsoft Dynamics AX 2012 Excel Add-in – Customer transactions Import

Purpose: The purpose of this document is to illustrate how to use Microsoft Dynamics AX 2012 Excel Add-in for import of customer transactions with required level of detail.

Challenge: Data model changes in Microsoft Dynamics related to high normalization and introduction of surrogate keys made some imports more complex. In fact the data model forming General Journal was not dramatically changed and import principle remains the same – populate the journal and then post the journal. Numerous fields are available on General Journal line level in Rich client to achieve required level of detail during import. In order to import customer transactions with required level of detail using Excel Add-in some additional work may be required.

Solution: Microsoft Dynamics AX 2012 ships with General Journal AIF Web Service (LedgerGeneralJournalService) which can be used in integration scenarios. Also General Journal AIF Web Service can be used in Excel for import of customer transactions. However General Journal AIF Web Service may not expose all fields which may be required for import such as Invoice, etc. In this walkthrough in order to import customer transactions using Excel the appropriate tables will be used instead. Some additional work will be done after initial import to align customer account.

Assumption: The assumption is that appropriate reference data such as customers, etc. was created in advance.

Data Model:

Table Name

Table Description

LedgerJournalTable

The LedgerJournalTable table contains all the defaulting and state information pertaining to a single journal. The transaction details of a journal are managed in the LedgerJournalTrans table.

LedgerJournalTrans

The LedgerJournalTrans table contains the transaction detail information that pertains to a single journal. The individual transaction lines are also referred to as voucher lines. The journal is a record in the LedgerJournalTable table.

Data Model Diagram:

Walkthrough:

AxdLedgerGeneralJournal Query

General Journal AIF Web Service doesn’t expose all fields which may be required for import such as Invoice, etc.

In order to bring Customer account information over to AX I introduced CustAccount field into LedgerJournalTrans table as shown below

CustAccount field is based on CustAccount EDT which in its turn has relation to CustTable table

After mentioned customizations will be introduced you will have to regenerate AIF Proxy classes in order to reflect changes in the data model. I used LedgerGeneralJournalService AIF Web Service because it has LedgerJournalTable and LedgerJournalTrans tables as data sources, this is exactly the tables I need AIF Proxy classes to be regenerated for.

Update document service

After you complete steps required to Update document service as it’s described in “Import Data” walkthrough you will need to generate incremental CIL.

Generate Incremental CIL

Connection

Add Tables

Dynamics AX Error

Solution:

- Add replacement key to VendTrans table {Field, RecId}

- Add replacement key to CustTrans table {Field, RecId}

- Add replacement key to LedgerJournalTrans table {Field, RecId}

- Add replacement key to ReasonTableRef table {Field, RecId}

- Add replacement key to VendBankAccount table {Field, RecId}

- Add replacement key to CustBankAccount table {Field, RecId}

- Add replacement key to BudgetSource table {Field, RecId}

- Add replacement key to BudgetTransactionLine table {Field, RecId}

Field Chooser

Accounting structure

Dynamics AX Error

When you unpress Field Chooser button you may see “The number of joins in the statement is X. This exceeds the maximum of 26. …” error

This error occurs because of numerous relations specified on LedgerJournalTrans and LedgerJournalTable tables. As opposite to AIF Web Service where the data set is strictly defined by the Query, in the case when raw tables are being used the system is building composite data set based on relations specified on tables/EDT level

In order to bypass this error you will have to change “Maximum buffer size (KB)” setting in Dynamics AX Server Configuration Utility and restart AX AOS

Dynamics AX Server Configuration Utility

LedgerJournalTable

Field Name

Field Description

Journal batch number

Name

Description

LedgerJournalTrans

Field Name

Field Description

Journal batch number

Voucher

Date

Company accounts

Account type

LedgerJournalTrans.CustAccount <custom>

Customer account

DefaultDimension.Department

Description

Debit

Credit

Currency

LedgerJournalTrans.Invoice

Invoice

Offset company accounts

Offset account type

OffsetLedgerDimension

OffsetLedgerDimension.Main Account

OffsetLedgerDimension.Department

Offset-transaction text

1)

2)

3)

Please note that I added Invoice field which is not included in General Journal AIF Web Service data set by default. Also to manipulate with Customer account I added custom CustAccount field, after initial import this field will be used in X++ Job to populate LedgerDimension field in LedgerJournalTrans table based on Customer account specified. In my previous walkthroughs I used different approach which doesn’t require the customization of AX data model (the structure of LedgerJournalTrans table) when I used Description field to bring Customer account info over to AX.

When you will try to publish LedgerJournalTrans table data you will see “Method AxdBase.getDimensionId must be overridden” error

Dynamics AX Error

This error occurs because there’s no behavior defined in Generic document AIF document class (AxdGenericDocument) which is used when you work with raw tables as it relates to LedgerDimension field(s) processing.

Please note that General Journal AIF document class does have this behavior defined, that’s why it can handle LedgerDimension field(s) fine.

Actually the actual LedgerDimension field(s) handling happens during deserialization in AxdLedgerGeneralJournal class, here in getDimensionId method the values get stored for future processing.

Solution:

The next logical step is to override getDimensionId method in AxdGenericDocument class assuming that we just want to import customer transactions for now

However with this code (stub) we can bypass the error but not populate LedgerDimension field(s) values appropriately. In order to populate LedgerDimension field(s) values I modified this method to look like the following

This will take care of populating Offset account on General Journal line level properly when using raw tables. Please note that Customer account field will be populated separately and then X++ job will be used to populate appropriate LedgerDimension value which corresponds to particular Customer account.

X++ Job

Sequence:

1. LedgerJournalTable – Publish Selected

2. LedgerJournalTrans – Publish Selected

Result:

Dynamics AX – General Journal

Dynamics AX – Execute X++ Job

Dynamics AX – General Journal lines

Dynamics AX – General Ledger Posting

Alternatives:

Alternatively General Journal AIF Web Service (LedgerGeneralJournalService) Query may be modified to accommodate for more fields required for import such as Invoice, etc. This approach is much easier to implement by the user.

After you customize the Query document service must be updated using Update document service function in Developer workspace and then incremental CIL must be generated.

As an alternative to introduction of brand new field CustAccount to bring over Customer account information to AX you can make use LedgerDimension.MainAccount field.

LedgerJournalTrans

This trick will require the customization of AxdGenericDocument AIF document class in order to handle special behavior associated with LedgerDimension field(s) (LedgerDimension, OffsetLedgerDimension) as shown below

Here I assume that in Account field I specify Customer account and in Offset account field I specify Ledger account (Clearing account).

Using these ideas to facilitate import effort the same result will be achieved! The difference is in the amount of customizations introduced in order to import the data.

SQL Trace:

Summary: For the purposes of small or medium data migration (data conversion) where performance is not a concern Excel can be used for import of customer transactions into Microsoft Dynamics AX 2012. General Journal AIF Web Service (LedgerGeneralJournalService) can be used in Excel for import of customer transactions. However General Journal AIF Web Service (LedgerGeneralJournalService) doesn’t expose all fields which may be required for import. In this case General Journal AIF Web Service (LedgerGeneralJournalService) Query may be customized to accommodate for more fields, or raw tables may be used instead. Excel template can be created and used for import of customer transactions.

In this document raw tables approach was implemented to import customer transactions with required level of detail to demonstrate the mechanics of the process. In another similar walkthrough dedicated to import of vendor transactions with required level of detail I’ll focus on General Journal AIF Web Service modification approach which is much easier to implement for the user.

Author: Alex Anikiev, PhD, MCP

Tags: Dynamics ERP, Dynamics AX 2012, Excel, Dynamics AX 2012 Excel Add-in, Data Import, Data Conversion, Data Migration, Application Integration Framework, Customer transactions.

Note: This document is intended for information purposes only, presented as it is with no warranties from the author. This document may be updated with more content to better outline the concepts and describe the examples. Please remove all Data Model changes introduced as a part of this demonstration once you complete data import exercise.

Wednesday, February 8, 2012

Dynamics AX 2012 Excel Add-in - Storage Dimensions

Dynamics AX 2012 Excel Add-in - Storage Dimensions

Purpose: The purpose of this document is to illustrate how to work with Storage Dimensions in Dynamics AX 2012 Excel Add-in.

Challenge: Data model changes in Dynamics AX related to high normalization and introduction of surrogate keys made import of data more complex. Additionally there are number of differences between Excel and AX Rich Client from UI standpoint when it comes to handling Inventory dimensions. AX Rich Client is obviously more dynamic comparing to Excel. AX Rich Client has a number of specialized classes to support Inventory dimensions related operations and UI.

Solution: Dynamics AX 2012 ships with the number of AIF Web Service which can be used in integration scenarios. However not all of them can be used in Excel at the moment for import of data. In order to manipulate with Storage Dimensions using Excel the appropriate tables can be used. In my example I’ll import required Storage Dimensions, then import Sales Orders information and specify Storage Dimensions related to Sales Order line.

Data Model:

Table Name

Table Description

InventSite

The InventSite table contains information about sites.

InventLocation

The InventLocation table contains information about warehouses.

WMSLocation

The WMSLocation table contains information about locations.

WMSPallet

The WMSPallet table contains information about pallets.

InventDim

The InventDim table contains values for inventory dimensions.

InventSum

The InventSum table contains information about the present and expected on-hand stock of items.

Data Model Diagram:

Inventory Dimensions

image

Red area highlights tables forming Product Dimensions data model

Green area highlights tables forming Storage Dimensions data model

Blue area highlights tables forming Tracking Dimensions data model

Storage Dimensions

image

In Rich Client when Inventory Dimensions are specified, for example, on Sales order line or Purchase order line the system will automatically create InventDim table record and allocate InventDimId value if specified combination of inventory dimensions doesn’t exist in InventDim table yet, otherwise existing InventDimId which corresponds to the specified combination will be re-used. This means that the system will not create InventDim table record for the combination which is not yet used. If you create Sales order line or Purchase order line programmatically using X++ you would use Tables\InventDim\findOrCreate method to assign proper InventDimId to SalesLine table buffer or PurchLine table buffer.

In Excel Add-in there’s no dedicated control related to InventDimId EDT (InventDimId field) yet to enable automatic creation of InventDim table record based on Inventory Dimensions - “segments”. I would anticipate that we have something similar to Excel Add-in segmented control for DimensionDynamicAccount EDT (LedgerDimension field).

InventDimId field lookup

LedgerDimension field lookup

image

image

If you modify AutoLookup field group in InventDim table to include {InventDimId, ConfigId, InventSizeId, InventColorId, InventSiteId, InventLocationId, WMSLocationId, WMSPalletId, InventBatchId, InventSerialId} fields then you can get full list of Inventory Dimensions displayed on Excel Add-in lookup form, however you will still have to specify existing InventDimId before you can create Sales order line or Purchase order line for specific combination of Inventory Dimensions.

In order to resolve this problem appropriate combinations of Inventory Dimensions will have to be created upfront and then Excel VLOOKUP function can be used to pull out the particular InventDimId and apply it to specific Sales order line or Purchase order line.

Excel Add-in can be used to create combinations of Inventory Dimensions in InventDim table.

Alternatively you can write X++ job that will programmatically create desired combinations of Inventory Dimensions for you. Please see the example of X++ job below

Storage Dimensions in Dynamics AX 2012 are Site, Warehouse, Location and Pallet.

Storage Dimensions Walkthrough:

Connection

Add Tables

Field Chooser

InventSite

Field Name

Field Description

Site

Name

SiteReqPolicy

Field Name

Field Description

Site

Use transfer journals for movements within site

InventLocation

Field Name

Field Description

Site

Warehouse

Name

Result

Dynamics AX – Site

Dynamics AX – Warehouse

Add Tables

Field Chooser

InventDim

Field Name

Field Description

<unbound>

Combination

InventDim.InventDimId

Dimension No.

InventDim.InventSiteId

Site

InventDim.InventLocationId

Warehouse

Please note that I added unbound Combination field into Ax_InventDim table

Combination field is simple concatenation of 2 strings {Site, Warehouse} with “” delimiter in the middle. This field will be used in VLOOKUP function during the import of Sales Order lines in order to put correct InventDimId value in SalesLine.InventDimId field.

Usually when you are doing Data Import you either don’t have InventDimId easily accessible or you do by opening Table Browser or another Excel tab with InventDim table data, and ultimately anyways you’ll have to copy and paste InventDimId value into, for example, SalesLine.InventDimId field.

In fact you will always have an information about what Site and Warehouse (in my example) this Sales Order line should belong to even not having InventDimId value.

That’s why I’m going introduce similar Combination field in Ax_SalesLine table to compare it against Combination field in Ax_InventDim table and automatically put required InventDimId value in SalesLine.InventDimId without a need to manually do copy and paste.

Publish Selected – InventDim

Result

Dynamics AX – Table Browser

Sales order ID number sequence

SalesTable

Field Name

Field Description

Currency

Customer account

Customer group

Invoice account

Language

Requested ship date

Sales order

SalesLine

Field Name

Field Description

<unbound>

Combination

Currency

Customer

Group

Requested ship date

Sales order

Item number

Quantity

Unit

Unit price

Net amount

SalesLine.InventDimId

Dimension No.

<unbound>

Site

<unbound>

Warehouse

Please note that I added similar unbound Combination field into Ax_SalesLine table. The difference here is that Site and Warehouse fields in Ax_SalesLine table are also unbound. Again, usually you have the information about Site and Warehouse (in my example) particular Sales Order line should belong, but you don’t have InventDimId value itself. This becomes critical when you have a lot of combinations of Inventory Dimensions to be introduced into the system as a part of Data Import which will support Sales Order lines.

Similarly Combination field is simple concatenation of 2 strings {Site, Warehouse} with “” delimiter in the middle and it will be used in comparison against Combination field in Ax_InventDim table in order to put correct InventDimId value into SalesLine.InventDimId field.

Publish Selected – Sales Line

Please note that bound InventDimId field in SalesLine table has a formula associated that uses VLOOKUP function. This is how we compare Combination fields in Ax_InventDim and Ax_SalesLine tables to find out about correct InventDimId value to be used in SalesLine.InventDimId field.

By other words, I’m looking for the value from Combination field from Ax_SalesLine table (1st parameter) in Ax_InventDim table (2nd parameter). If exact match (4th parameter) was found then the value in 2nd column (3rd parameter) will be returned as the result.

Please note that by default the category in InventDimId field is Text which has to be changed to General to be able to apply the formula.

Please note that there’re number of prerequisites in order to apply VLOOKUP formula correctly.

Important:

1. Combination field has to be left-most field in Ax_SalesLine table

2. No duplicate values are allowed in Combination field in Ax_InventDim table because we are looking for the exact match

3. You can use static named ranges, absolute cells coordinates or table name(s) in Excel to effectively define table_array value (2nd parameter in VLOOKUP function)

You may define Filter criteria to fetch only certain InventDim table records into Ax_InventDim table in Excel. Consequently it may happen that there’s no match found in Ax_InventDim table, so Excel will put #NA value into the cell. In order to substitute #NA (Not Available) to something more meaningful you can change VLOOKUP formula to be

=IF(ISNA(VLOOKUP([Combination],Ax_InventDim,2,FALSE)),"AllBlank",VLOOKUP([Combination],Ax_InventDim,2,FALSE))

Please note that “AllBlank” represents the record in InventDim table which has no Inventory Dimensions defined

After Sales Order line(s) information gets published the system will reread the information and display the results to you, consequently you will have a value displayed in InventDimId field in SalesLine table instead of VLOOKUP formula.

Result:

Dynamics AX – Sales Order

Dynamics AX – Sales Order Invoice

SQL Trace:

Summary: For the purposes of small or medium data migration (data conversion) where performance is not a concern Excel can be used for import of data into Dynamics AX 2012. Although there’s no AIF Web Service to import Inventory Dimensions combinations (into InventDim table) upfront, appropriate tables can be used instead. Excel template can be created and used for import of data.

Author: Alex Anikiev, PhD, MCP

Tags: Dynamics ERP, Dynamics AX 2012, Excel, Dynamics AX 2012 Excel Add-in, Data Import, Data Conversion, Data Migration, Application Integration Framework, Inventory Dimensions, Storage Dimensions.

Note: This document is intended for information purposes only, presented as it is with no warranties from the author. This document may be updated with more content to better outline the concepts and describe the examples. It’s recommended that all Data Model changes introduced as a part of this demonstration will be removed once you complete data import exercise.