From July 9th till 13th we will be at #MSInspire. See you there!

How to Creating Sales Order in Dynamics AX 2012 Through X++

How to Creating Sales Order in Dynamics AX 2012 Through X++
08 May 2015

Creating Sales Order in Dynamics AX 2012 Through X++

Hi guys, in this post I’m going to show you how to create a sales order in Dynamics AX 2012 through X++. This is very common activity that you’ll come across if you’re working on the AX Sales and Marketing module so you should know how to go about it. Let’s take a look.

So I’m going to create a sales order by running a job (below), but you can also create a class to create sales orders, if you want to use it in multiple places. Here’s the code you can use to create a sales order in Dynamics AX 2012 through X++.

static void CreateSalesOrder(Args _args)


//declaring variables

SalesTable salesTable;

SalesLine salesLine;

NumberSeq numberSeq;

SalesFormLetter salesFormLetter;;


//creating sales order header

//getting sales order id from number sequence

numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());


salesTable.SalesId = numberSeq.num();


salesTable.CustAccount = ‘US-001’;



if (!salesTable.validateWrite()) {

throw Exception::Error;



//creating sales order line

salesLine.SalesId = salesTable.SalesId;

salesLine.ItemId = ‘D0001’;

salesLine.SalesQty = 2;

salesLine.LinePercent = 1;

salesLine.createLine(true, // Validate

true, // initFromSalesTable

true, // initFromInventTable

true, // calcInventQty

true, // searchMarkup

true  // searchPrice



//confirm sales order

salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);


//displaying sales order id



And that’s it.

About Folio3 Dynamics Services

FDS (Folio3 Dynamics Services) is a dedicated division of Folio3 that specializes in Microsoft Dynamics AX, Dynamics CRM, Dynamics NAV and Dynamics GP based development, customization and integration services. Our main focus is on Enterprise Mobility. We firmly believe that opening up Microsoft Dynamics AX and other products to iOS Android, Windows 8 and Windows Phone users will have a huge impact on organizational agility and productivity.

ABOUT Folio3 Dynamics Services

As Dynamics AX experts we specialize in Dynamics AX development including Dynamics AX customization, integration, implementation and mobility solutions. If you have a Dynamics AX development requirement you would like to discuss or would like to know more about our Dynamics AX development services, please get in touch with us.


Raza Rabbani

Latest From Our Blog
Difference between Dynamics CRM and the Dynamic...
Record a Purchase Invoice In Dynamics AX
November 28, 2019
A lot of people tend to get confused between the Microsoft Dynamics CRM and the Dynamics AX CRM, Read our detailed comparison between dynamics crm ...
Read more
7 Ways Dynamics 365 Finance and Operations Boos...
dynamics 365 finance
November 9, 2018
Introduction Launched by Microsoft, Dynamics 365 ERP is one of the most effective for businesses today. It is perfect to save the time, effort and ...
Read more
The Ultimate Guide to Dynamics 365 HR Payroll P...
dynamics hr payroll
October 30, 2018
For any business, irrespective of its size, payroll processing is one of the most important functions. Payroll processing is a method through which...
Read more