static void postSalesInvoice(Args _args)
{
SalesFormLetter salesFormLetter;
SalesTable salesTable;
SalesId salesId = ‘005063’;
System.Exception error;
str strError;
CustInvoiceJour custInvoiceJour;
;ttsBegin;
try
{
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));
}}
else
{
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));
}
ttscommit;
}