Wednesday, May 23, 2012

Dynamics AX 2012 Excel Add-in – Issues and Solutions (Index was outside the bounds of the array)

Dynamics AX 2012 Excel Add-in –
Issues and Solutions (Index was outside the bounds of the array)
Purpose: The purpose of this document is to outline some issues you may encounter when using Dynamics AX 2012 Excel Add-in for import of data and provide solutions to resolve them.


Issue: 'Index was outside the bounds of the array'.


Reason: This issue occurs because some mandatory fields are not specified for particular business entity. As the result validation of request XML will fail and exception will be thrown in Classes\AifWcfInterceptor\AfterReceiveRequest (CIL: AifWcfInterceptor.AfterReceiveRequest.xpp). However this exception will not be handled properly in external calling code (Dynamics AX 2012 Excel Add-in) and instead of meaningful "Invalid document schema" error message the user will see misleading "Index was outside the bounds of the array" error message. Please note that you can see the real error message in Event Viewer and/or Exceptions form assuming that Logging is enabled for appropriate Inbound port. In this example I will focus on Budget entries import using Budget Transactions Service AIF Web Service.  


Dynamics AX Error

Solution: Please specify all mandatory fields for particular business entity you are trying to import before you Publish. In this example initially I didn't specify LedgerDimension field on BudgetTransactionLine table that is a part of Budget Transactions Service AIF Web Service data set which caused 'Index was outside the bounds of the array' error. After I properly specified all mandatory fields on business entities being imported the import process is successful.

Document data sources


Please note that BudgetTransactionsService AIF Web Service is activated as Document data source


Inbound port


Please note that Logging mode is 'All document versions' which is required for troubleshooting. Also it's important to mention that BudgetTransactionsService AIF Web Service operations (create, update, delete, read, etc) were exposed through OfficeAddins Enhanced Inbound port which was successfully activated. Alternatively you can activate BudgetServices Services Group which also contains BudgetTransactionsService AIF Web Service.


Select Data


Data (Header – left and Line – right)

Please note that I specified the very minimum number of fields for BudgetTransactionHeader and BudgerTransactionLine tables looking at Red asterisk icon (Mandatory field) or Yellow Key icon (Foreign Key) next to the respective field in the Field Chooser
BudgetTransactionHeader
BudgetTransactionLine


Please note that LedgerDimension field has its own Dimension icon (not marked with Red asterisk), however LedgerDimension is also mandatory field in BudgetTransactionLine table


Publish


Event Viewer
If you take a look at error message logged in Event Viewer you will see the following error message "Object Server 01:  An error has occurred in the services framework.  Method: AifMessageInspector::AfterReceiveRequest.  Error: System.ServiceModel.FaultException`1[Microsoft.Dynamics.Ax.Services.AifFault]: Invalid document schema. The following error was returned:  The element 'BudgetTransLine' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction' has invalid child element 'Price' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction'. List of possible elements expected: 'LedgerDimension' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction'. (Fault Detail is equal to Microsoft.Dynamics.Ax.Services.AifFault)" which describes the real issue with document schema.


Exceptions form
Same thing can be seen in Exceptions form in Dynamics AX 2012 which shows the same error message 'Invalid document schema. The following error was returned:  The element 'BudgetTransLine' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction' has invalid child element 'Price' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction'. List of possible elements expected: 'LedgerDimension' in namespace 'http://schemas.microsoft.com/dynamics/2008/01/documents/BudgetTransaction'' as well as request XML message in History form in Dynamics AX 2012


To resolve this issue I'll specify LedgerDimension field for Budget entry line
I also specified more fields for Budget entry header and line for informational purposes


Publish
This time import process is successful


Result

Tags: Dynamics ERP, Dynamics AX 2012, Excel, Dynamics AX 2012 Excel Add-in, Data Import, Data Conversion, Data Migration, Application Integration Framework, Issue, Problem, Solution, Resolution.


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 issues and describe the solutions.


Author: Alex Anikiev, PhD, MCP

Tuesday, May 1, 2012

Dynamics AX 2012 Excel Add-in – Issues and Solutions (Cannot have 0 columns)

Dynamics AX 2012 Excel Add-in –  Issues and Solutions (Cannot have 0 columns)

Purpose: The purpose of this document is to outline some issues you may encounter when using Dynamics AX 2012 Excel Add-in for import of data and provide solutions to resolve them.

Issue: 'Cannot have 0 columns'.

Reason: This issue occurs because some tables in Microsoft Dynamics AX 2012 don't have any fields for specific functional purpose or for the purposes of table inheritance just being another logical level in the hierarchy. In the case if such table with no columns will be related to the main table you will see 'Cannot have 0 columns' error even despite the fact that Replacement key may be specified on the table.

Dynamics AX Error

Solution: Please create fictitious (fake) field(s) in the tables related to the main table which have no columns. For example, you may encounter 'Cannot have 0 columns' error when doing Purchase orders data import because Tax1099BoxDetail table and PurchCommitmentLine_PSN table have no columns and they are linked to PurchLine table by Surrogate key. In order to resolve this issue I'll add fake 'ID' field (String) to Tax1099BoxDetail table and PurchCommitmentLine_PSN table so each table will now have at least one field.

PurchLine table is linked to Tax1099BoxDetail table by Surrogate key

PurchLine table is linked to PurchCommitmentLine_PSN table by Surrogate key

You can find all tables related to PurchLine table by looking at Relations node at table level as depicted above, or at EDT (Extended data type) level for EDTs used on PurchLine table fields. 

When you try to add PurchTable table and PurchLine table to Excel Add-in you will see the following error

In order to resolve this you will have to add Replacement keys to the following tables

ReasonTableRef table Replacement key

AgreementHeader table Replacement key

SourceDocumentHeader table Replacement key

SourceDocumentLine table Replacement key

When you will try to add PurchTable table and PurchLine table again you will see the following error

In order to resolve this you will have to add Replacement keys to the following tables

Tax1099BoxDetail table Replacement key

Important: Please note that Tax1099BoxDetail table has no fields

PurchCommitmentLine_PSN table Replacement key

Important: Please note that PurchCommitmentLine_PSN table has no fields

When you try to Publish selected for PurchLine table you will see the following error

This is because Tax1099DetailBox table and PurchCommitmentLine_PSN table have no columns and they are linked to PurchLine table by Surrogate key

In order to resolve this you will have to add fictitious (fake) field(s) to Tax1099DetailBox table and PurchCommitmentLine_PSN table so they have at least one field. In this case I added 'ID' field (String) to Tax1099DetailBox table and PurchCommitmentLine_PSN table. I didn't plan to introduce any data into Tax1099DetailBox table and PurchCommitmentLine_PSN table, so I also added 'ID' field to the Replacement key with the assumption that this key will be unique.

Tax1099DetailBox table new 'ID' field (String)

PurchCommitmentLine_PSN table new 'ID' field (String)

Now if you do Publish selected for PurchLine table you will have expected result

You can apply the same logic when resolving this error for different type of data import using Excel Add-in

It's recommended to remove these data model modifications once you complete data import activities

Please make sure to refresh Caches after you change the data model and restart Excel before publishing data. It's recommended to restart AOS to make sure that the latest data model changes will be taken into account in Excel Add-in

Tags: Dynamics ERP, Dynamics AX 2012, Excel, Dynamics AX 2012 Excel Add-in, Data Import, Data Conversion, Data Migration, Application Integration Framework, Issue, Problem, Solution, Resolution.

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 issues and describe the solutions.

Author: Alex Anikiev, PhD, MCP