Create Sales order and posting Invoice through code of X++

Hi All,
Today, I will be posting on how to create sales order through x++.

The following lines of code create sales header part.
static void createSalesTable(CustAccount _custAccount)
SalesTable salesTable;
NumberSeq NumberSeq;
NumberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
salesTable.SalesId = NumberSeq.num();
salesTable.CustAccount = _custAccount;
The following lines of code create Sales line part.
static void createSalesLine(SalesId _salesId, ItemId _itemId)

SalesLine salesLine;
salesLine.SalesId = _salesId;
salesLine.ItemId = _itemId;
salesLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes); // searchPrice

The following lines of code posts invoice of SO

static void postSalesInvoice(Args _args)
// Define a class variable according to the  type of posting being performed
SalesFormLetter_Invoice invoice;
SalesTable salesTable;
// Select the salesTable to update
salesTable = SalesTable::find(“SO-101297”);
// Create a new object of the SalesFormLetter_Invoice by using the construct-method in //SalesFormLetter
invoice = SalesFormLetter::construct(DocumentStatus::Invoice);
// Post the invoice of SO
invoice.update(salesTable, SystemDateGet(), SalesUpdate::All,AccountOrder::None, false, true);
// Set to true to print the invoice

Thanks & Happy DaXing……..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: