Project Item Journal D365FO
Dynamics technical consultants often times receive the requirements to create the journal using X++ where we couldn't use data entity for any reason.
So, In this article, I am writing the sample which may help you a lot to create a project Item journal easily.
public void
createProjectInventJournal(ProjectJournalContract
_projectJournal)
{
InventDim inventDim;
InventJournalName InventJournalName;
InventJournalTable inventJournalTable;
InventJournalTableData journalTableData = JournalTableData::newTable(inventJournalTable);
InventTable inventTable;
ProjTable projTable;
AWCFieldServIntegrtionMainAccount ServiceOffsetAccount=this.findServiceMainAccount(AWCFieldServiceIntegrationType::ProjectItem);
ProjectJournalTransContract journalTransContract;
if(_projectJournal.getProjectJournalTransCount()==0)
{
return;
}
journalTransContract =
_projectJournal.getProjectJournalTrans(0);
select projTable
where
projTable.ProjId==journalTransContract.ProjectId;
select inventTable
where
inventTable.itemId==journalTransContract.ItemId;
select InventJournalName
where InventJournalName.JournalType==InventJournalType::project
&&
InventJournalName.isFSJournal==NoYes::Yes;
inventJournalTable.JournalId =
journalTableData.nextJournalId();
inventJournalTable.JournalType=InventJournalType::project;
journalTableData.initFromJournalName(InventJournalName);
inventJournalTable.insert();
InventJournalTrans inventJournalTrans;
InventJournalTransData journalTransData =
journalTableData.journalStatic().newJournalTransData(inventJournalTrans,
journalTableData);
journalTransData.initFromJournalTable();
inventJournalTrans.TransDate = today();
inventJournalTrans.ProjId =journalTransContract.ProjectId;
inventJournalTrans.ProjCategoryId = journalTransContract.ProjectCateId;
inventJournalTrans.initFromProjTable(projTable);
inventJournalTrans.initFromInventTable(inventTable);
inventJournalTrans.Qty = journalTransContract.QtyUsed;
inventJournalTrans.PriceUnit = journalTransContract.CostPrice;
inventJournalTrans.ProjUnitID = journalTransContract.Unit;
inventJournalTrans.Worker = HcmWorkerLookup::currentWorker();
inventJournalTrans.LedgerDimension = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(ServiceOffsetAccount.MainAccountId).RecId);
inventJournalTrans.activityNumberModified();
inventDim.clear();
inventDim.InventSiteId = journalTransContract.Site;
inventDim.InventLocationId
=journalTransContract.Location;
inventDim.wMSLocationId =
journalTransContract.Warehouse;
inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
//other fields
journalTransData.create();
}
Hi also add this to get the correct Cost Amount
ReplyDeleteinventJournalTrans.CostAmount = inventJournalTrans.calcCostAmount();
Do you realize there is a 12 word phrase you can say to your partner... that will induce intense feelings of love and instinctual attractiveness for you deep inside his heart?
ReplyDeleteThat's because hidden in these 12 words is a "secret signal" that triggers a man's instinct to love, please and protect you with his entire heart...
=====> 12 Words Who Trigger A Man's Desire Impulse
This instinct is so built-in to a man's genetics that it will make him try better than ever before to make your relationship as strong as it can be.
Matter-of-fact, fueling this influential instinct is so binding to having the best possible relationship with your man that the moment you send your man one of these "Secret Signals"...
...You will soon notice him expose his heart and soul for you in a way he never expressed before and he will distinguish you as the only woman in the world who has ever truly tempted him.