Hello everyone,
Today i would like to post a code snippet for creating and posting a project journal, by using this we can also Create/post Fee(Revenue), Hour, Expense type journals as well.
static void ProjJournalCreateAndPost(Args _args)
{
// Variable declaration
ProjJournalTable jourTable;
ProjJournalTrans jourTrans;
ProjJournalTableData jourTableData;
ProjJournalTransData jourTransData;
ProjJournalStatic jourStatic;
ProjJournalCheckPost jourPost;
ttsBegin;
// Inserting the Header Mandatory fields
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalId = jourTableData.nextJournalId();
// Journal Types can be change to Hour, // Expense using the Enum "ProjJournaltype"
jourTable.JournalType = ProjJournalType::Revenue;
jourTable.JournalNameId = 'FEE';
jourTableData.initFromJournalName( ProjJournalName::find(jourTable.JournalNameId));
jourStatic = jourTableData.journalStatic();
// Inserting Line details for that particulat ProjectId
jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
jourTransData.initFromJournalTable();
jourTrans.initValue();
jourTrans.ProjId = '000059';
jourTrans.initFromProjTable( ProjTable::find(jourTrans.ProjId));
jourTrans.TransDate = systemDateGet();
jourTrans.LinePropertyId = "Billable";
jourTrans.ProjTransDate = jourTrans.TransDate;
jourTrans.CategoryId = 'Setup';
jourTrans.setHourCostPrice();
jourTrans.setHourSalesPrice();
jourTrans.TaxItemGroupId = ProjCategory::find(jourTrans.CategoryId).TaxItemGroupId;
jourTrans.Worker = HcmWorker::findByPersonnelNumber('000062').RecId;
jourTrans.Txt = 'Posting Automation';
jourTrans.Qty = 10;
jourTransData.create();
//Always best practice to check validate method before inserting
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),'PJJ-00363');
// Posting the journal
jourPost = ProjJournalCheckPost::newJournalCheckPost(true,true,JournalCheckPostType::Post,tableNum(ProjJournalTable),jourTable.JournalId);
jourPost.run();
}
Proud to be a DAX Developer :-)
Hi,
ReplyDeleteHow do we know the validation result ?
Thanks in advance.
Hi RamaKrishna,
DeleteCan you be more specific ?
Best regards,
Nanda Kishore V
Hi,
ReplyDeleteis there any classes to create journals like AxLedgerJournalTable and AxLedgerJournalTrans ?