Friday, May 31, 2019

Get Invoice Journal Id after posting Sales Invoice from multiple packing slips using X++

SalesFormLetter_Invoice SalesFormLetter;
TmpFrmVirtual           tmpFrmVirtual;
List                    il;
;
il = new List(Types::Record);
// insert each packing slip RecId into the TmpFrmVirtual table
for (i = 1; i <= conlen(PScontainer); i++)
{
            packingSlipRecId = conpeek(PScontainer, i);
            custPackingSlipJour = custPackingSlipJour::findRecId(packingSlipRecId);     

            tmpFrmVirtual.NoYes     = true;
            tmpFrmVirtual.TableNum  = custPackingSlipJour.TableId;
            tmpFrmVirtual.RecordNo  = custPackingSlipJour.RecId;
            tmpFrmVirtual.Id        = custPackingSlipJour.SalesId;
            ttsBegin;
            tmpFrmVirtual.insert();
            ttsCommit;
            // add record into the List
            il.addEnd(tmpFrmVirtual);
}
// post invoice from multiple packing slips
        salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
        salesFormLetter.printFormLetter(false);
        salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, false, false, false, false, il.pack());
        // get the posted invoice journal recid
        invoiceJourRecId    = salesFormLetter.getOutputContract().parmJournal().RecId;


or  get a container of posted journals

CustInvoiceTrans        custInvTrans;
Set                     postedJournalList;
Set                     allPostedJournals = new Set(Types::Record);
SetEnumerator           enumAllPostedJournal;
Set                     postedJournalTransList;
SetEnumerator           enumPostedJournalTransList;


postedJournalList   = Set::create(SysOperationHelper::base64Decode(salesFormLetter.getOutputContract().parmAllJournals()));
allPostedJournals   = Set::union(allPostedJournals, postedJournalList);
postedJournalTransList      = Set::create(SysOperationHelper::base64Decode(salesFormLetter.getOutputContract().parmJournalLines()));
enumPostedJournalTransList  = postedJournalTransList.getEnumerator();

while(enumPostedJournalTransList.moveNext())
 {
        custInvTrans      = enumPostedJournalTransList.current();
        // process the data here
 }




Thursday, May 30, 2019

Convert from Transaction currency to Accounting currency

CurrencyExchangeHelper  currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), _invoicejournal.InvoiceDate);

lineCharges = currencyExchangeHelper.calculateTransactionToAccounting(_invoicejournal.CurrencyCode, lineCharges, true);


Set up Onebox VM for D365 FO with non-organization microsoft account

With the release of the new VHD 10.0.37, I have tried to create a Onebox VM in my laptop instead of using the cloud hosted environment and f...