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.
|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.
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.
static void SalesOrdersXppImport(Args _args)
salesTable.SalesId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
salesTable.DeliveryDate = str2Date(#DeliveryDate, 213);
salesTable.CustAccount = #Customer;
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;
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
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.
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
In the setup tab, we have to define:
- Tax information
- Posting information
- Withholding tax
- Date and time
- Administration part also
In the address tab, we have to add address delivery address information of the customer.
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
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:
- Sales order.
Sales Line Form
In this form, we have to define the:
- Unit price
- Line amount is automatically calculated i.e., qty * Unit price.
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.
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.
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.
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.