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.


Noc Folio3