Faster and Better Dynamics AX with Import Utility: In AX 2012, user has to create a sales order manually. First, he or she has to create sales order header, then sales order line. After confirmation, he or she has to create picking list and then packing list. After that, the user has to invoice that sales order. We suggest using import utility to save time and effort. This is the biggest advantage of import utility. Here, we will share the code that a user would require to import sales order through the job.

Purpose: The purpose of this blog is to illustrate how to write a required minimum X++ code in Microsoft Dynamics AX 2012 to import sales orders.

Challenge: Data model changes in Microsoft Dynamics AX 2012 related to high normalization and introduction of surrogate keys made some imports more complex. However, the structure of tables comprising sales order header/lines didn’t change. Please note that after you import sales orders, you may need to perform full/partial physical and/or financial update if required.

Solution: Appropriate tables buffers (SalesTable, SalesLine) will be used when writing X++ code in Microsoft Dynamics AX 2012 to import sales orders. Alternatively, AxBC classes may be used instead of table buffers.

Data Model

Table Name Table Description
SalesTable The SalesTable table contains all sales order headers regardless of whether they have been posted.
SalesLine The SalesLine table contains all sales order lines regardless of whether they have been posted.
InventDim The InventDim table contains values for inventory dimensions.

Data Model Diagram

In data model diagram,there is linking between selectable> salesline > Inventdim.

Dynamics Ax 1 2686951 


ttsBegin: Use ttsBegin to start a transaction.

clear: The clear method clears the contents of the record.

initValue: The initValue method initializes the fields of the record.

initFrom*: The initFrom* methods usually populate the fields of the child record based on the fields on the parent record. Example is initFromSalesTable method on SalesLine table.

validateWrite: The validateWrite method checks whether the record can be written.

write: The write method writes the record to the database.

insert: The insert method inserts the record into the database.

doInsert: The doInsert method inserts the record into the database. Calling doInsert ensures that any X++ code written in the insert method of the record is not executed. Calling insert always executes the X++ code written in the insertmethod of the record.

ttsCommit: Use ttsCommit to commit a transaction. 

Source Code

static void SalesOrdersXppImport(Args _args)







SalesTable      salesTable;

SalesLine       salesLine;

InventDim       inventDim;




//Order header



salesTable.SalesId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();

salesTable.DeliveryDate = str2Date(#DeliveryDate, 213);

salesTable.CustAccount = #Customer;


if (salesTable.validateWrite())



//Order line


inventDim.InventSiteId = “1”;

inventDim.InventLocationId = “12”;




salesLine.ItemId = #ItemId;


salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

salesLine.SalesQty = #Qty;

salesLine.RemainSalesPhysical = salesLine.SalesQty;

salesLine.SalesUnit = #Unit;

salesLine.QtyOrdered = salesLine.calcQtyOrdered();

salesLine.RemainInventPhysical = salesLine.QtyOrdered;


if (salesLine.validateWrite())





throw error(“Order line”);



throw error(“Order header”);










Result: Please note that we assigned SalesId programmatically from Number sequence

Product – Sales price

Sales Order Processing in AX 2012



First, we have to create sales order> then confirm the sales order > then go for the picking route > then go for the packing slip > then finally make the invoice. We have to follow these steps to make a sales invoice.

Results After Importing the Sales Order

After importing the data, we have to check all the form to be sure that the data in the form is correct.


Follow the Steps to Create Sales Order to Sales Invoice


Sales Header Form

Dynamics Ax 4 7254153

In the sales header form, we have to have specify the details in which the sales order is going to the customer. Likewise, we have to have specify customer details like name, address, phone number, email ID, site, warehouse and much more.

General Tab

In the general tab, we have to specify customer’s basic details like:

1) Customer name

2) Customer address

3) Customer account

4) Email ID

5) Site

6) Warehouse


Setup Tab


 In the setup tab, we have to define:

  • Tax information
  • Posting information
  • Inventory
  • Withholding tax
  • Date and time
  • Administration part also

Address Tab

In the address tab, we have to add address delivery address information of the customer.

Dynamics Ax 6 6020342


Price and Discount Tab


 In the price discount tab, users have to fill the:

  • Currency that is used for the transaction.
  • Payment mode that is by cash or check.
  • Discount that has been provided to the customer group.

Foreign Trade Tab

Dynamics Ax 8 2382167

In the foreign trade tab, we have to specify the:

  • Transport mode that is by road, by air, etc.
  • Port where the delivery has been made like Mudra etc.

Financial Dimension Tab

Depending upon the requirement, user has to fill the dimension for the financial impact with details like:

  • Branch
  • Department
  • Months
  • Purpose
  • Sales order.

Sales Line Form

Dynamics Ax 10 6611169

In this form, we have to define the:

  • Item
  • Quantity
  • Unit price
  • Line amount is automatically calculated i.e., qty * Unit price.

Packing Slip

Path: Accounts receivable>Common>Sales orders>All sales orders>Pick and Pack tab.

In this, we have to create packing slip for the customer. All the sales order confirmation line has been put in the packing slip line and we have to check and create packing slip for the same sales order followed by creation of invoice.


Sales Invoice

Dynamics Ax 12 9236382 

Path: Accounts receivable>Common>Sales orders>All sales orders>Sales Invoice Tab.

In this, we have to justify the mandatory fields that are:

  • Sales invoice number
  • Sales invoice date

After that, we have to post the sales invoice and bill has to be sent to the customer for payment.

Note: After that, we have to check the posting entries to ensure that these are going to right transaction. We have to check ledger transaction and the physical voucher for this sales order in AX 2012.

Inventory Transaction

Check that item in the ledger transaction that the quantity you have defined in the sales order has to be reduced in the ledger transaction or not.

Voucher Transaction

Dynamics Ax 14 6729806 

Check the Voucher Transaction report to ensure that the entries have been posted into the correct ledger. If yes, then the sales order you imported is correct.


In this blog, Microsoft Dynamics AX development team explained how to write a required minimum X++ code in Microsoft Dynamics AX 2012 to import sales orders. Appropriate table buffers were used when writing X++ code in Microsoft Dynamics AX 2012. This approach can be very handy for POC’s or in situation with always changing requirements. You can also use Microsoft Dynamics AX Excel Add-in to import relatively small amounts of data. Please consider using DIXF (Data Import Export Framework) for import of significant amounts of data when performance is an important consideration. DIXF (Data Import Export Framework) provides a standard template for import of sales orders. With this, Import Utility user can save a lot of time. This helps in creating sales order through the job rather than creating it manually.

New NetWeaver Information at

Very Helpfull



User Rating: Be the first one !