static void Job_CreateInventCounting(Args _args)
{
InventJournalName inventJournalName;
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventDim inventDim;
JournalCheckPost inventJournalCheckPost;
JournalId journalId;
InventSum inventSum;
container offSetAcctPattern;
int linenum;
;
inventJournalName = InventJournalName::find(“ICnt”); //<–Important
inventJournalTable.initFromInventJournalName(inventJournalName);
inventJournalTable.SystemBlocked = true;
inventJournalTable.insert();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.TransDate = systemdateget();
inventJournalTrans.ItemId = “1163”;
//inventDim.initFromInventTable(inventJournalTrans.inventMovement().inventTable(),InventItemOrderSetupType::Invent,inventDim);
inventDim.InventSiteId = ‘1’;
inventDim.InventLocationId = ’11’;
inventDim.configId = ’01’;
inventDim = InventDim::findOrCreate(inventDim);
inventJournalTrans.InventDimId = inventDim.inventDimId;
inventSum = InventSum::find(inventJournalTrans.ItemId,inventJournalTrans.InventDimId);
InventSum.reread(); //<– Important because InventSum using cache data.
//info(strFmt(‘%1’,inventSum.AvailPhysical));
inventJournalTrans.InventOnHand = InventSum.AvailPhysical; //<–Important
inventJournalTrans.Counted = 1200; //<–Important
inventJournalTrans.Qty = inventJournalTrans.Counted – inventJournalTrans.InventOnHand;
inventJournalTrans.insert();
linenum++;
journalId = inventJournalTable.JournalId;
info(strFmt(‘%1’,journalId));
inventJournalCheckPost =InventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post, inventJournalTable);
inventJournalCheckPost.run();
update_recordSet inventJournalTable
setting SystemBlocked = false, NumOfLines = linenum
where inventJournalTable.JournalId == journalId;
}