Pages

Banner 468 x 60px

 

Wednesday, February 15, 2023

Export data from AX to CSV file through X++

0 comments

 TextBuffer          textBuffer = new TextBuffer();

    FileNameFilter      Filter = ["CSV file", "*.csv"];

    FileName            FileName;

    #WinAPI

    LedgerJournalTrans  LocLedgerJournalTrans, TxtLedgerJournalTrans;

    ;

    super();

 FileName = winapi::getSaveFileName(infolog.hWnd(), filter, @"c:\...\desktop", "Save as CSV file","csv","Create Payment Permata");

    if(!FileName)

        return ;


    while select sum(AmountCurDebit), LedgerDimension, OffsetLedgerDimension, CurrencyCode, PaymentMethod, TransDate, BankAccountId, JournalNum

        from LocLedgerJournalTrans

            Group by LedgerDimension, OffsetLedgerDimension, CurrencyCode, PaymentMethod, TransDate, BankAccountId, JournalNum

                order by LineNum

                where LocLedgerJournalTrans.JournalNum == LedgerJournalTrans.JournalNum

                    && LocLedgerJournalTrans.accounttype == LedgerJournalACType::Vend

    {

        textBuffer.appendText(strfmt("%1,", VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.LedgerDimension)).AccountID));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));


        if(LocLedgerJournalTrans.PaymentMethod != PaymentMethod::OVB)

        {

            textBuffer.appendText(strfmt("%1,", VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.LedgerDimension)).RegistrationNum));

        }

        else

        {

            textBuffer.appendText(strfmt("%1,", ""));

        }


        textBuffer.appendText(strfmt("%1,", VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.LedgerDimension)).Name));


        // fixing

        textBuffer.appendText(strfmt("%1,", VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.LedgerDimension)).AccountNum));

        // end fixing


        textBuffer.appendText(strfmt("%1,", LocLedgerJournalTrans.CurrencyCode));

        //textBuffer.appendText(strfmt("%1,", any2real(num2str0((LocLedgerJournalTrans.AmountCurDebit), 0, 0, 1,0)))); //real2int(LocLedgerJournalTrans.AmountCurDebit)));

        //textBuffer.appendText(strfmt("%1,", LocLedgerJournalTrans.AmountCurDebit));


        textBuffer.appendText(strfmt("%1,",Num2Str(LocLedgerJournalTrans.AmountCurDebit, 0, 99, DecimalSeparator::Auto, ThousandSeparator::None)));


        info(strfmt("%1,", any2real(num2str0((LocLedgerJournalTrans.AmountCurDebit), 0, 0, 1,0))));


        select firstFast txt from

            TxtLedgerJournalTrans

                where TxtLedgerJournalTrans.JournalNum == LocLedgerJournalTrans.JournalNum

                && TxtLedgerJournalTrans.LedgerDimension == LocLedgerJournalTrans.LedgerDimension;



        textBuffer.appendText(strfmt("%1,", strReplace(TxtLedgerJournalTrans.txt, ",", "")));

        textBuffer.appendText(strfmt("%1,", ''));

        textBuffer.appendText(strfmt("%1,", vendtable::find(VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.LedgerDimension)).VendAccount).Email));

        textBuffer.appendText(strfmt("%1,", LocLedgerJournalTrans.PaymentMethod));

        textBuffer.appendText(strfmt("%1,", "0"));

        textBuffer.appendText(strfmt("%1,", "0"));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", "PT XXX"));

        textBuffer.appendText(strfmt("%1,", BankAccountTable::find(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.OffsetLedgerDimension)).AccountNum));

        textBuffer.appendText(strfmt("%1,", BankAccountTable::find(DimensionStorage::ledgerDimension2AccountNum(LocLedgerJournalTrans.OffsetLedgerDimension)).CurrencyCode));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", "Jakarta"));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText(strfmt("%1,", ""));


        /*if(vendtable::find(VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LedgerJournalTrans.LedgerDimension)).VendAccount).name() like '*Bpk*)

        {

            textBuffer.appendText(strfmt("%1,", "1"));

        }

        else

        {

            if(vendtable::find(VendBankAccount::findByVendAccount(DimensionStorage::ledgerDimension2AccountNum(LedgerJournalTrans.LedgerDimension)).VendAccount).name() like '*Ibu*)

            {

                textBuffer.appendText(strfmt("%1,", "1"));

            }

            else

                {

                    textBuffer.appendText(strfmt("%1,", "2"));

                }

        }*/


        textBuffer.appendText(strfmt("%1,", "2"));

        textBuffer.appendText(strfmt("%1,", ""));

        textBuffer.appendText("\n");//next row

    }


    if (textBuffer.toFile(FileName))

    {

        info( strfmt("File Generated as %1.Total %2 Lines",FileName,textBuffer.numLines()));

        winapi::shellExecute(FileName);

    }

}

Read more...

Confirm PO Error : The source document lines cannot be finalized until the status is Confirmed in AX 2012

0 comments

 

Confirm PO Error : The source document lines cannot be finalized until the status is Confirmed

SOLUTION : 
Open AOT > Table > BudgetSourceTracking 

In Table BudgetSourceTracking find this PO Number => change the status from Draft to Confirmed
and try to Confirm your PO

Read more...

A financial dimension value is based on the LAND-00013 record and has been used on a transaction. You cannot delete the LAND-00013 record AX 2012

 A financial dimension value is based on the LAND-00013 record and has been used on a  transaction. You cannot delete the LAND-00013 record ...