Create Sales Order X++
public class SalesOrderDemo { private void new() { } public static SalesOrderDemo construct() { return new SalesOrderDemo(); } public void createSalesOrder() { SalesTable salesTable; SalesLine salesLine; CustTable custTable= CustTable::find("US-007"); AxSalesTable axsalesTable; AxSalesLine axSalesLine; SalesFormLetter salesFormLetter; NumberSeq numberSeq; #OCCRetryCount if (! this.validate()) throw error(""); try { ttsbegin; //Create Sales order // ttsBegin; numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId()); numberSeq.used(); salesTable.SalesId = numberSeq.num(); salesTable.initValue(); salesTable.CustAccount = 'US-007'; salesTable.initFromCustTable(); salesTable.InventSiteId = '1'; salesTable.InventLocationId = '11'; if (!salesTable.validateWrite()) { throw Exception::Error; } salesTable.insert(); //ttsCommit; info(strFmt("Sales order '%1' has been created", salesTable.SalesId)); while select tmpFromVirtual { salesLine.clear(); salesLine.initFromSalesTable(salesTable); salesLine.SalesId = salesTable.SalesId; salesLine.ItemId = tmpFromVirtual.ItemId; salesLine.createLine(true, true, true, true, true, true); } if (1) { throw error('canceled'); } //SO confirmation salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation); salesFormLetter.update(salesTable); // SO invoicing salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice); salesFormLetter.update(salesTable); ttscommit; } catch (Exception::Deadlock) { retry; } catch (Exception::UpdateConflict) { if (appl.ttsLevel() == 0) { if (xSession::currentRetryCount() >= #RetryNum) { throw Exception::UpdateConflictNotRecovered; } else { retry; } } else { throw Exception::UpdateConflict; } } }