问题
i'm wondering if anyone can help me figure out how to programatically set the document number and date in the general journal trans, under the tab invoice. I'm trying to post to the general journal in ax 2012 with x++. I currently have this code that works but there is no method under the ledgerjournal trans to set the document no or date. infact alot of the setters are missing and only has linenum account type, journal num etc etc. How can i set these fields? below i have some code
static void TestLedgerJournalImport(Args _args)
{
// Set these variables.
LedgerJournalNameId journalName = 'GenJrn';
SelectableDataArea company = '019';
TransDate transactionDate = 30\6\2012;
str line1MainAccount = '131310';
str line1FullAccount = '131310--';
str line2MainAccount = '131310';
str line2FullAccount = '131310-10-';
str line2Dimension1Name = 'Department';
str line2Dimension1Value = 'ACCT';
LedgerGeneralJournalService ledgerGeneralJournalService;
LedgerGeneralJournal ledgerGeneralJournal;
AfStronglyTypedDataContainerList journalHeaderCollection;
LedgerGeneralJournal_LedgerJournalTable journalHeader;
AifEntityKeyList journalHeaderCollectionKeyList;
RecId journalHeaderRecId;
AfStronglyTypedDataContainerList journalLineCollection;
LedgerGeneralJournal_LedgerJournalTrans journalLine1;
AifMultiTypeAccount journalLine1LedgerDimension;
LedgerGeneralJournal_LedgerJournalTrans journalLine2;
AifMultiTypeAccount journalLine2LedgerDimension;
AifDimensionAttributeValue journalLine2Dim1;
AfStronglyTypedDataContainerList journalLine2DimensionCollection;
;
ledgerGeneralJournalService = LedgerGeneralJournalService::construct();
ledgerGeneralJournal = new LedgerGeneralJournal();
// Create journal header.
journalHeaderCollection = ledgerGeneralJournal.createLedgerJournalTable();
journalHeader = journalHeaderCollection.insertNew(1);
journalHeader.parmJournalName(journalName);
// Create journal lines.
journalLineCollection = journalHeader.createLedgerJournalTrans();
// Line 1
journalLine1 = journalLineCollection.insertNew(1);
journalLine1.parmLineNum(1.00);
journalLine1.parmCompany(company);
journalLine1.parmTransDate(transactionDate);
journalLine1.parmAccountType(LedgerJournalACType::Ledger);
journalLine1.parmTxt('Test journal transaction');
journalLine1.parmAmountCurDebit(100.00);
journalLine1LedgerDimension = journalLine1.createLedgerDimension();
journalLine1LedgerDimension.parmAccount(line1MainAccount);
journalLine1LedgerDimension.parmDisplayValue(line1FullAccount);
journalLine1.parmLedgerDimension(journalLine1LedgerDimension);
// Line 2
journalLine2 = journalLineCollection.insertNew(2);
journalLine2.parmLineNum(2.00);
journalLine2.parmCompany(company);
journalLine2.parmTransDate(transactionDate);
journalLine2.parmAccountType(LedgerJournalACType::Ledger);
journalLine2.parmTxt('Test journal transaction');
journalLine2.parmAmountCurCredit(100.00);
journalLine2LedgerDimension = journalLine2.createLedgerDimension();
journalLine2DimensionCollection = journalLine2LedgerDimension.createValues();
journalLine2Dim1 = new AifDimensionAttributeValue();
journalLine2Dim1.parmName(line2Dimension1Name);
journalLine2Dim1.parmValue(line2Dimension1Value);
journalLine2DimensionCollection.add(journalLine2Dim1);
journalLine2LedgerDimension.parmAccount(line2MainAccount);
journalLine2LedgerDimension.parmDisplayValue(line2FullAccount);
journalLine2LedgerDimension.parmValues(journalLine2DimensionCollection);
journalLine2.parmLedgerDimension(journalLine2LedgerDimension);
// Insert records.
journalHeader.parmLedgerJournalTrans(journalLineCollection);
ledgerGeneralJournal.parmLedgerJournalTable(journalHeaderCollection);
journalHeaderCollectionKeyList =
LedgerGeneralJournalService.create(ledgerGeneralJournal);
journalHeaderRecId =
journalHeaderCollectionKeyList.getEntityKey(1).parmRecId();
info(strFmt("LedgerJournalTable.Recid = %1", int642str(journalHeaderRecId)));
}
回答1:
Don't do it like that, you're making more work for yourself. I just wrote this example for you. I hacked up a more complex piece of code I wrote, so the offsetDefaultDimension I just left in for some example code.
static void Job3(Args _args)
{
AxLedgerJournalTable journalTable = AxLedgerJournalTable::construct();
LedgerJournalTable ledgerJournalTable;
LedgerJournalName ledgerJournalName = LedgerJournalName::find('GenJrn');
AxLedgerJournalTrans journalTrans = AxLedgerJournalTrans::construct();
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionAttributeValueSetStorage dimStorage;
LedgerDimensionAccount ledgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum('131310'));
journalTable.parmJournalName(ledgerJournalName.JournalName);
journalTable.parmJournalType(ledgerJournalName.JournalType);
journalTable.save();
ttsBegin;
ledgerJournalTable = LedgerJournalTable::findByRecId(journalTable.ledgerJournalTable().RecId, true);
// The name gets reset if no journal number is provided, so we can just update afterwords
ledgerJournalTable.Name = 'My Custom Journal Name/Description';
ledgerJournalTable.update();
ttsCommit;
journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(today());
journalTrans.parmCurrencyCode('USD');
journalTrans.parmTxt('AlexOnDAX.blogspot.com');
journalTrans.parmDocumentNum('MyDocNumber');
journalTrans.parmDocumentDate(today() - 1);
journalTrans.parmAccountType(LedgerJournalACType::Ledger);
journalTrans.parmLedgerDimension(DimensionAttributeValueCombination::find(ledgerDimension).RecId);
journalTrans.parmAmountCurDebit(100.00);
journalTrans.save();
info("Done");
}
来源:https://stackoverflow.com/questions/27850784/how-to-post-document-date-and-document-number-in-general-journal