With the following code you can create and validate/post a Project Journal in Dyn365 or Ax 2012.
A standard code example can be analyzed here:
class: JmgPostStandardSystem
method: showProjectFeeJournal
Here is my code snippet:
//Variable
ProjJournalTable jourTable;
ProjJournalTableData jourTableData;
ProjJournalStatic jourStatic;
ProjJournalCheckPost jourPost;
ProjJournalTransData jourTransData;
ProjJournalTrans jourTrans;
MyTableLine myLine;
ttsBegin;
// Inserting the Header Mandatory fields
jourTableData = JournalTableData::newTable(jourTable);
jourTransData = jourTableData.journalStatic().newJournalTransData(jourTrans,jourTableData);
jourTable.JournalId = jourTableData.nextJournalId();
// Journal Types can be change to Hour, Expense using the Enum ProjJournaltype
jourTable.JournalType = ProjJournalType::Revenue;
jourTable.JournalNameId = _parameters.JournalNameId;
jourStatic = jourTableData.journalStatic();
jourTableData.initFromJournalName(jourTableData.journalStatic().findJournalName(jourTable.JournalNameId));
while select myLine
{
// Inserting Line details for that particulat ProjectId
jourTrans.clear();
jourTransData.initFromJournalTable();
jourTrans.initValue();
jourTrans.ProjId = _projTable.ProjId;
jourTrans.initFromProjTable(ProjTable::find(jourTrans.ProjId));
jourTrans.TransDate = systemDateGet();
jourTrans.LinePropertyId = "Billable";
jourTrans.ProjTransDate = jourTrans.TransDate;
jourTrans.setHourCostPrice();
jourTrans.setHourSalesPrice();
jourTrans.TaxItemGroupId = ProjCategory::find(jourTrans.CategoryId).TaxItemGroupId;
jourTrans.Txt = myLine.Description;
jourTrans.Qty = myLine.SalesQty;
jourTrans.CurrencyId = myLine.Currency;
jourTrans.SalesPrice = myLine.SalesPrice;
jourTransData.create();
}
if (jourtable.validatewrite())
{
jourtable.insert();
}
ttsCommit;
info(strFmt("Journal '%1' has been created", jourTable.JournalId));
// Validating the journal
jourPost = ProjJournalCheckPost::newJournalCheckPost(true,true,JournalCheckPostType::Check,tableNum(ProjJournalTable),jourTable.JournalId);
// Posting the journal
jourPost = ProjJournalCheckPost::newJournalCheckPost(true,true,JournalCheckPostType::Post,tableNum(ProjJournalTable),jourTable.JournalId);
//jourPost.run();