miércoles, 28 de marzo de 2012

Crear y leer Archivos Dynamics ax 2012

static void Job_File_IO_TextIo_Write_Read(Args _args)
{
    TextIo txIoRead,
         txIoWrite;
    FileIOPermission fioPermission;
    container containFromRead;
    int xx,
        iConLength;
    str sTempPath,
        sFileName = "Test_File_IO.txt",
        sOneRecord;
    ;
    // Get the temporary path.
    sTempPath = WINAPI::getTempPath();
    info("File is at: " + sTempPath + sFileName);

    // Assert permission.
    fioPermission = new FileIOPermission
        (sTempPath + sFileName ,"RW");
    fioPermission.assert();
 
    // If the test file already exists, delete it.
    if (WINAPI::fileExists(sFileName))
    {
        WINAPI::deleteFile(sTempPath + sFileName);
    }
    
    // Open a test file for writing.
    // "W" mode overwrites existing content, or creates the file.
    txIoWrite = new TextIo( sTempPath + sFileName ,"W");

    // Write records to the file.
    txIoWrite.write("Hello        World.");
    txIoWrite.write("The sky is blue.");
    txIoWrite.write("");
    txIoWrite.write("// EOFile");

    // Close the test file.
    txIoRead = null;

    // Open the same file for reading.
    txIoRead = new TextIo(sTempPath + sFileName ,"R");
    // Read the entire file into a container.
    containFromRead = txIoRead.read();

    // Loop through the container of file records.
    while (containFromRead)
    {
        sOneRecord = "";
        iConLength = conLen(containFromRead);
        // Loop through the token in the current record.
        for (xx=1; xx <= iConLength; xx++)
        {
            if (xx > 1) sOneRecord += " ";
            sOneRecord += conPeek(containFromRead ,xx);
        }
        info(sOneRecord);

        // Read the next record from the container.
        containFromRead = txIoRead.read();
    }

    // Close the test file.
    txIoRead = null;
    // Delete the test file.
    WINAPI::deleteFile(sTempPath + sFileName);

    // revertAssert is not really necessary here,
    // because the job (or method) is ending.
    CodeAccessPermission::revertAssert();
}
Fuente: http://msdn.microsoft.com/en-us/library/cc967403.aspx

martes, 13 de marzo de 2012

Crear Asiento Ax 2012

 LedgerVoucher   lv;
    NumberSeq       numberSeq;
   currencyExchangeHelper currencyExchangeHelper ;
    LedgerVoucherTransObject LedgerVoucherTransObject;
   LedgerVoucherObject LedgerVoucherObject;
    ;
    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), today());
    ttsBegin;
    numberSeq = NumberSeq::newGetVoucher(LedgerParameters::numRefLedgerExchAdjVoucher());

    lv = LedgerVoucher::newLedgerPost(
        DetailSummary::Detail,
        SysModule::Ledger,
        numberSeq.parmNumberSequenceCode());

    LedgerVoucherObject= LedgerVoucherObject::newVoucher(numberSeq.voucher(),today(), SysModule::Ledger,LedgerTransType::Invent);
    lv.addVoucher(LedgerVoucherObject);

    LedgerVoucherTransObject=LedgerVoucherTransObject::newTransactionAmountDefault(
            LedgerVoucherObject,//("ABI-000437"),
            LedgerPostingType::LedgerJournal,
            DimensionDefaultingService::serviceCreateLedgerDimension(5637157573),           // Ledger account
            Ledger::find(Ledger::current()).AccountingCurrency,
            2004,              // Amount
            currencyExchangeHelper);
     lv.addTrans(LedgerVoucherTransObject);

     LedgerVoucherTransObject=LedgerVoucherTransObject::newTransactionAmountDefault(
            LedgerVoucherObject,//("ABI-000437"),
            LedgerPostingType::LedgerJournal,
            DimensionDefaultingService::serviceCreateLedgerDimension(5637158025),           // Ledger account
            Ledger::find(Ledger::current()).AccountingCurrency,
            -2004,              // Amount
            currencyExchangeHelper);
     lv.addTrans(LedgerVoucherTransObject);
    lv.end();
    ttsCommit