通过x ++代码在LedgerJournalTransCustPaym表单中创建一条新记录

时间:2013-09-03 19:44:55

标签: axapta dynamics-ax-2009

我需要在LedgerJournalTrans到x ++代码中创建一个reord。

调试时我发现类LedgerJournalEngine_CustPayment用于启动表单

LedgerJournalEngine_CustPayment  = new LedgerJournalEngine_CustPayment(element)

以后

LedgerJournalEngine.initValue(LedgerJournalTrans);

在为accountNum数据源字段modified()的{​​{1}}方法执行的方法分配LedgerJournalTrans:AccountNum后,还element.accountNumModifiedPost();等。

尝试通过代码实现相同的功能时,我无法启动类LedgerJournalEngine_CustPayment以及系统LedgerJournalTransCustPaym形式的其他方法。

请帮忙.. 乔伊斯

1 个答案:

答案 0 :(得分:1)

LedgerJournalEngine *类主要由表单用于在事件和数据源操作之前/之后执行工作和执行代码。你要做的是,完成所有必要的ledgerJournalTrans字段可能更有意义,然后做一个.insert()。以下是我编写的一些代码,它们会使用引擎执行您想要的操作:

static void Job81(Args _args)
{
    LedgerJournalEngine_CustPayment ledgerJournalEngine;
    LedgerJournalTable              ledgerJournalTable;
    LedgerJournalTrans              ledgerJournalTrans;
    NumberSeq                       numberSeq;
    Voucher                         voucher;
    ;

    // This just selects the header you are inserting into
    select firstonly ledgerJournalTable where ledgerJournalTable.JournalNum == 'GB 0056226';

    if (!ledgerJournalTable)
        throw error ("Unable to find journal table record");


    ledgerJournalTrans.initValue();

    numberSeq = NumberSeq::newGetNumFromCode(ledgerJournalTable.VoucherSeries);

    if (numberSeq)
    {
        ledgerJournalTrans.Voucher      = numberSeq.num();
        voucher                         = ledgerJournalTrans.Voucher;
    }

    ledgerJournalTrans.JournalNum       = ledgerJournalTable.JournalNum;
    ledgerJournalTrans.TransDate        = SystemDateGet();
    ledgerJournalTrans.AccountType      = LedgerjournalACType::Cust;
    ledgerJournalTrans.AccountNum       = '100003';

    ledgerJournalEngine = LedgerJournalEngine::construct(LedgerJournalType::CustPayment);
    ledgerJournalEngine.newJournalActive(ledgerJournalTable);
    ledgerJournalEngine.accountModified(ledgerJournalTrans);
    ledgerJournalTrans.AmountCurCredit  = 10;
    ledgerJournalTrans.OffsetAccountType    = ledgerJournalTable.OffsetAccountType;
    ledgerJournalTrans.OffsetAccount        = ledgerJournalTable.OffsetAccount;
    ledgerJournalTrans.CurrencyCode         = CompanyInfo::standardCurrency();
    ledgerJournalEngine.currencyModified(ledgerJournalTrans);
    ledgerJournalTrans.insert();

    if (numberSeq   && ledgerJournalTrans.Voucher   == voucher)
    {
        numberSeq.used();
    }
    else
    {
        if (numberSeq)
            numberSeq.abort();
    }

    info("Done");
}