28 Mar 2013

How to create sales order through X++

creating sales order in a book and I was able to compile a code for posting sales order invoice. I thought I should share on my blog. It might be useful for some one.

Code for creating Sales order

SalesTableType and SalesLinetype. Insert() should be called for creating the sales order. Example is as follows. I am currently looking for code that can contains example code of creating invoice from scratch. I will send you the code in an hour.

static void createSalesTable(CustAccount _custAccount)
{
SalesTable salesTable;
NumberSeq NumberSeq;
;

NumberSeq =NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
salesTable.SalesId = NumberSeq.num();
salesTable.initValue();
salesTable.CustAccount = _custAccount;
salesTable.initFromCustTable();
salesTable.insert();
}

Example: Create a Sales Line

static void createSalesLine(SalesId _salesId, ItemId _itemId)
{
SalesLine salesLine;
;
salesLine.clear();
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
}

Code for posting Sales order Invoice

static void createSalesOrder(Args _args)
{
SalesFormLetter formLetterObj;
formLetterObj = SalesFormLetter::construct(DocumentStatus::Invoice);
formLetterObj.update(SalesTable::find(“SO-101248″));
}

No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...