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

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello

    Trying to update Financial dim on products via Excel add-in. Get the following error when publishing updates of financial dim in InventTable. Have migratated products via DIXF.

    "Invalid document schema. The following error was returned: The 'http://schemas.microsoft.com/dynamics/2008/01/documents/InventTable:UnitVolume' element is invalid - The value '0.00156' is invalid according to its datatype 'http://schemas.microsoft.com/dynamics/2008/01/sharedtypes:AxdExtType_ItemVolume' - The FractionDigits constraint failed. The FractionDigits constraint failed.
    "
    "Invalid document schema. The following error was returned: The 'http://schemas.microsoft.com/dynamics/2008/01/documents/InventTable:NetWeight' element is invalid - The value '0.586625' is invalid according to its datatype 'http://schemas.microsoft.com/dynamics/2008/01/sharedtypes:AxdExtType_ItemNetWeight' - The FractionDigits constraint failed. The FractionDigits constraint failed.
    "

    Have validated the product with no problems. Have also tested to change from . to , as a sepearter for both volume and weight fractions.

    Any ideas?

    //Gustaf

    ReplyDelete
  3. This is a very nice article to understand the concept of the new pipeline. The pipeline is a way to connect various things together to perform a collective operation. As per machine learning service providers, this technology is one of the amazing concepts of AI and machine learning.

    ReplyDelete