AX 2012: Post Sales Invoice using X++

AX 2012: Post Sales Invoice using X++

static void postSalesInvoice(Args _args)
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘005063’;
System.Exception error;
str strError;
CustInvoiceJour custInvoiceJour;

salesTable = SalesTable::find(salesId);

if (salesTable && salesTable.SalesStatus == SalesStatus::Delivered)
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No, NoYes::Yes);

if (salesFormLetter.parmJournalRecord().TableId == tableNum(CustInvoiceJour))
custInvoiceJour = salesFormLetter.parmJournalRecord();
info(strFmt(‘Sales Order #:%1 has been successfully posted and Invoice #:%2 is created!’, custInvoiceJour.SalesId, custInvoiceJour.InvoiceId));

info(strFmt(‘%1 does not exsists or null in the system, please try again!’, salesId));

catch (Exception::CLRError)
error = CLRInterop::getLastException();
strError = error.ToString();

info(strfmt(‘%1’, strError));
info(strFmt(‘%1 failed to post, please try again!’, salesId));


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s