US 408 365 4638

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

Table of Contents

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;;

ttsBegin;

//creating sales order header

//getting sales order id from number sequence

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

numberSeq.used();

salesTable.SalesId = numberSeq.num();

salesTable.initValue();

salesTable.CustAccount = ‘US-001’;

salesTable.initFromCustTable();

//validate

if (!salesTable.validateWrite()) {

throw Exception::Error;

}

salesTable.insert();

//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

);

ttsCommit;

//confirm sales order

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

salesFormLetter.update(salesTable);

//displaying sales order id

info(salesTable.SalesId);

}

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.

Related Post