Sunday, October 26, 2014

Write Data to Text file from AX

// Write Data to Text file from AX

static void WriteTextfile(Args _args)
{
    CustTable   custTable;
    BinData     binData;
    TextBuffer  textBuffer;
    boolean     header;
    ;
    header = true;
    textBuffer = new TextBuffer();
    textBuffer.setText('');

    while select custTable
    {
        header = true;
        if (header)
        {
              textBuffer.appendText(strfmt("%1 - %2 \r\n",custTable.AccountNum,CustTable::find(custTable.AccountNum).name()));
              header = false;
        }
        textBuffer.appendText(strfmt('\t"%1","%2","%3","%4","%5","%6","%7","%8"\r\n',
                    custTable.AccountNum,custTable.AccountStatement,custTable.Currency,custTable.CashDisc,
                    custTable.DlvTerm,custTable.InvoiceAccount,custTable.CustGroup,custTable.DlvMode));
    }
    textBuffer.getText();
    binData = new BinData();
    binData.setStrData(textBuffer.getText());
    binData.saveFile(@"d:\ValidationFileGenerationTest.txt");

}

Implement the lookup on Runbase class in ax 2012

// Implement the lookup on Runbase class

DialogRunbase dialogform = Dialog::newFormnameRunbase(formstr(custTableLookup),this);

Create Default Dimension through X++

 // Create Default Dimension through X++]


static void CreateDefaultDimen(Args _args)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;

    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully
    container               conAttr = ["Department", "ExpensePurpose", "Item"];
    container               conValue = ["00000028", "Training", "1000"];
    str                     dimValue;

    for (i = 1; i <= conLen(conAttr); i++)
    {
        dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

        if (dimensionAttribute.RecId == 0)
        {
            continue;
        }

        dimValue = conPeek(conValue,i);

        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
            dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();
    info(strFmt("%1",result));
}

All Account Payable Module Import



Account Payable Module;

filename        = dialogFilename.value();
    transdate        = dialogFromDate.value();
    journalNameId   = dialogledger.Value();
    impBal          = dialogimpBal.value();
    journalName     = dialogJournalName.value();
    journalTxt      = dialogJournalTxt.value();

AP à invoice Journal Import:

    LedgerJournalName   ledgerJournalName;
    AxLedgerJournalTrans                trans  = new AxLedgerJournalTrans();
    AxLedgerJournalTable                header = new AxLedgerJournalTable();
    str 60                    invoiceNumber,vendorAccount,txt,dimensn,offdimensn,offsetAccount,ApprovedBy;
    DirPartyTable           dirPartyTable;
    HcmWorker               hcmWorker;
    container               dimm,offdim;
    Amount                  amountCurDebit,amountCurCredit;
    first  = true;
    csvFile = new CommaTextIo(filename, 'r');
    csvFile.inFieldDelimiter(',');
    readCon = csvFile.read();
    try
    {
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();

            if(readCon)
            {
                if (first)
                {
                    header.parmJournalName(journalNameId);
                    select ledgerJournalName where ledgerJournalName.JournalName == journalNameId;
                    header.parmJournalType(ledgerJournalName.JournalType);

                    header.save();
                    first = false;
                }
                if (readCon )//dont insert first record of file : header
                    {
                        Transactiondate = transdate;
                        invoiceNumber = conPeek(readCon,1);
                        vendorAccount = conPeek(readCon,2);
                        txt = conPeek(readCon,3);
                        currencycode = conPeek(readCon,4);
                        amountCurDebit = conPeek(readCon,5);
                        amountCurCredit = conPeek(readCon,6);
                        offsetAccount = conPeek(readCon,7);
                        ApprovedBy = conPeek(readCon,8);
                        trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
                        dimensn = strFmt("%1,%1",vendorAccount);//strFmt("%1-%2-%3,%1,2,department,%2,costcenter,%3",ledgerAccount,department,costcenter);
                        dimm = str2con(dimensn);
                        trans.parmAccountType(LedgerJournalACTypE::Vend);
                        trans.parmLedgerDimension(DimensionStorage::getDynamicAccount(vendorAccount, LedgerJournalACType::vend)); //AxdDimensionUtil::getLedgerAccountId(dimm));
                        trans.parmTxt(txt);
                        select hcmworker where hcmWorker.PersonnelNumber == ApprovedBy;
                        trans.parmApprover(hcmworker.RecId);
                        trans.parmApproved(NoYes::Yes);
                        trans.parmDocumentDate(TransDate);
                        trans.parmTransDate(TransDate);
                        trans.parmInvoice(invoiceNumber);
                        trans.parmAmountCurDebit(AmountCurDebit);
                        trans.parmAmountCurCredit(AmountCurCredit) ;
                        trans.parmCompany(curext());
                        trans.parmCurrencyCode(currencycode);
                        trans.parmExchRate(1);
                        offdimensn = strFmt("%1,%1",offsetAccount);
                        offdim =str2con(offdimensn);
                        trans.parmOffsetLedgerDimension( DimensionStorage::getDynamicAccount(offsetAccount, LedgerJournalACType::Bank));
                        trans.parmOffsetAccountType(LedgerJournalACTypE::Bank);                        trans.parmVoucher(NumberSeq::newGetVoucherFromId((LedgerJournalName::find(JournalNameId).NumberSequenceTable)).voucher());
                        Trans.currentRecord().insert();
                        inserted++;
                        trans.save();
                    }
            }
       }
        ttsCommit;
    icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

    args = new Args();
    args.record(LedgerJournalTable::find(header.ledgerJournalTable().JournalNum ));

    new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);

//
//
APà Payment Journal Import:
LedgerJournalName       ledgerJournalName;
    AxLedgerJournalTrans    trans  = new AxLedgerJournalTrans();
    AxLedgerJournalTable    header = new AxLedgerJournalTable();
    str                     invoiceNumber,vendorAccount,txt,dimensn,offdimensn,offsetAccount;
    container               dimm,offdim;
    Amount                  amountCurDebit,amountCurCredit;
    MainAccount             mainAccount;
    VendTable               vendTable;
    first  = true;

    csvFile = new CommaTextIo(filename, 'r');

    csvFile.inFieldDelimiter(',');
    readCon = csvFile.read();
    try
    {
        ttsBegin;
        while(csvFile.status() == IO_Status::OK)
        {
            icount++;
            readCon = csvFile.read();

            if(readCon)
            {


                if (first)
                {
                    header.parmJournalName(journalNameId);
                    select ledgerJournalName where ledgerJournalName.JournalName == journalNameId;
                    header.parmJournalType(ledgerJournalName.JournalType);

                    header.save();
                    first = false;
                }


                if (readCon && icount )//dont insert first record of file : header
                    {

                        Transactiondate = transdate;
                        invoiceNumber = conPeek(readCon,1);
                        vendorAccount = conPeek(readCon,2);
                        txt = conPeek(readCon,3);
                        currencycode = conPeek(readCon,4);
                        amountCurDebit = conPeek(readCon,5);
                        amountCurCredit = conPeek(readCon,6);
                        offsetAccount = conPeek(readCon,7);

                        trans.parmJournalNum(header.ledgerJournalTable().JournalNum);


                        dimensn = strFmt("%1,%1",vendorAccount);//strFmt("%1-%2-%3,%1,2,department,%2,costcenter,%3",ledgerAccount,department,costcenter);
                        dimm = str2con(dimensn);

                        trans.parmAccountType(LedgerJournalACTypE::Vend);

                        trans.parmLedgerDimension(DimensionStorage::getDynamicAccount(vendorAccount, LedgerJournalACType::vend)); //AxdDimensionUtil::getLedgerAccountId(dimm));
                        trans.parmInvoice(invoiceNumber);
                        trans.parmTxt(txt);

                        trans.parmDocumentDate(TransDate);
                        trans.parmTransDate(TransDate);

                        trans.parmAmountCurDebit(AmountCurDebit);

                        trans.parmAmountCurCredit(AmountCurCredit) ;

                        trans.parmCompany(curext());
                        trans.parmCurrencyCode(currencycode);

                        trans.parmExchRate(1);
                        offdimensn = strFmt("%1,%1",offsetAccount);
                        offdim =str2con(offdimensn);

                        mainAccount = mainAccount::findByMainAccountId(offsetAccount);
                        if(!mainAccount)
                        {
                            trans.parmOffsetLedgerDimension( DimensionStorage::getDynamicAccount(offsetAccount, LedgerJournalACType::Bank));
                            trans.parmOffsetAccountType(LedgerJournalACTypE::Bank);
                        }
                        else
                        {
                            trans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offdim));
                            trans.parmOffsetAccountType(LedgerJournalACTypE::Ledger);
                        }
                        trans.parmVoucher(NumberSeq::newGetVoucherFromId((LedgerJournalName::find(JournalNameId).NumberSequenceTable)).voucher());
                        Trans.currentRecord().insert();

                        inserted++;

                        trans.save();


                    }

            }


        }
        ttsCommit;
     icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

    args = new Args();
    args.record(LedgerJournalTable::find(header.ledgerJournalTable().JournalNum ));

    new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);
//
//

Import Completed

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))] final class InventUpd_ReservationCls_SAN_Extension {     void updateNow()     {         if(mo...