At first glance it's easy. Let's open AOT. Then we find corresponding Menu Item in \Menu Items\Action\InventJournalPost. Open class InventJournalCheckPost... And looking at main() method of this class we are coming to conclusion that this class is tightly tied to the journalForm. What's a pity!
So let's try to write own code.
Look at main() method:
static void main(Args args) { InventJournalCheckPost journalCheckPost; journalForm journalForm; ; journalForm = journalForm::fromArgs(args); journalCheckPost = InventJournalCheckPost::newFromForm(args,journalForm); journalForm.runbaseMainStart(); if (!journalCheckPost.PROMPT())First of all we need to get rid of journalForm.
{ if (! journalCheckPost.BatchInfo().parmBatchExecute()) journalForm.runbaseMainCancel(); return; } try { journalCheckPost.run(); journalForm.runbaseMainEnd(journalCheckPost,false);
} catch (Exception::Error) { journalForm.runbaseMainEnd(journalCheckPost,true); } }
Let's rewrite newFromForm() method. The parameters wich passing into this method are used to achieve InventJournalTable. So we may just pass InventJournalTable into our new method.
JournalCheckPost getJournalCheckPost(InventJournalTable _inventJournalTable) { // \Menu Items\Action\InventJournalPost switch(inventJournalTable.journalType) { case InventJournalType::Movement: case InventJournalType::LossProfit: case InventJournalType::Transfer: case InventJournalType::BOM: case InventJournalType::Count: case InventJournalType::project: case InventJournalType::Asset: journalCheckPost_Mov = InventJournalCheckPost_Movement::newJournalCheckPost( false,true, JournalCheckPostType::Post, _inventJournalTable.tableId, _inventJournalTable.journalId); // journalTransData = _journalForm.JournalTransData(); // if (journalTransData) // journalCheckPost_Mov.parmVoucher(journalTransData.journalTrans().voucher); return journalCheckPost_Mov; case InventJournalType::TagCounting: journalCheckPost = InventJournalCheckPost_Tag::newJournalCheckPost( false, true, JournalCheckPostType::Post, inventJournalTable.tableId, _inventJournalTable.journalId); return journalCheckPost_Tag; } }Look at JournalFormTable class. It extends journalForm class.
Inside of runbaseMainStart() method we may find following line
journalTableData.updateBlock(JournalBlockLevel::None,JournalBlockLevel::System,false);
inside of runbaseMainCancel() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
and inside of runbaseMainEnd() method:
journalTableData.updateBlock(JournalBlockLevel::System,JournalBlockLevel::None,false);
That's enough. Now we may rewrite main() method:
// Posting start. According to \Classes\InventJournalCheckPost // journalForm.runbaseMainStart(); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::None, JournalBlockLevel::System, false); journalCheckPost = getJournalCheckPost(inventJournalTable); if (!journalCheckPost.PROMPT()) { if (! journalCheckPost.BatchInfo().parmBatchExecute()) { // journalForm.runbaseMainCancel(); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false); } return; } try { journalCheckPost.run(); // journalForm.runbaseMainEnd(journalCheckPost,false); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false); } catch (Exception::Error) { // journalForm.runbaseMainEnd(journalCheckPost,true); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, true); } // Posting endFinally, we are ready to write our remarkable job:
static void JobInventJournalPost(Args _args) { InventJournalCheckPost_Movement journalCheckPost_Mov; InventJournalCheckPost_Tag journalCheckPost_Tag; InventJournalCheckPost journalCheckPost; InventJournalTable inventJournalTable; InventJournalId inventJournalId = 'Inv002372'; JournalCheckPost getJournalCheckPost(InventJournalTable _inventJournalTable) { // \Menu Items\Action\InventJournalPost switch(_inventJournalTable.journalType) { case InventJournalType::Movement: case InventJournalType::LossProfit: case InventJournalType::Transfer: case InventJournalType::BOM: case InventJournalType::Count: case InventJournalType::project: case InventJournalType::Asset: journalCheckPost_Mov = InventJournalCheckPost_Movement::newJournalCheckPost( false,true, JournalCheckPostType::Post, _inventJournalTable.tableId, _inventJournalTable.journalId); // journalTransData = _journalForm.JournalTransData(); // if (journalTransData) // journalCheckPost_Mov.parmVoucher(journalTransData.journalTrans().voucher); return journalCheckPost_Mov; case InventJournalType::TagCounting: journalCheckPost = InventJournalCheckPost_Tag::newJournalCheckPost( false, true, JournalCheckPostType::Post, _inventJournalTable.tableId, _inventJournalTable.journalId); return journalCheckPost_Tag; } } ; inventJournalTable = InventJournalTable::find(inventJournalId); if(inventJournalTable) { // Posting start. According to \Classes\InventJournalCheckPost // journalForm.runbaseMainStart();
journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::None, JournalBlockLevel::System, false); journalCheckPost = getJournalCheckPost(inventJournalTable); if (!journalCheckPost.PROMPT()) { if (! journalCheckPost.BatchInfo().parmBatchExecute()) {
// journalForm.runbaseMainCancel(); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false); }
return;
} try { journalCheckPost.run(); // journalForm.runbaseMainEnd(journalCheckPost,false); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, false); } catch (Exception::Error) { // journalForm.runbaseMainEnd(journalCheckPost,true); journalTableData::updateBlockServer( inventJournalTable, JournalBlockLevel::System, JournalBlockLevel::None, true); } // Posting end }
Copyright © 2008 Ruslan Goncharov
6 comments:
Jesus!.. dig deeper and write a simplier code:
InventJournalCheckPost::newPostJournal(inventJournalTable).run();
Hi Ruslan,
Thanks for your blogs . It is very useful for my projects.
Now im using Ax2009, Here Posting a BOM journal is bit different , i.e first it needs to finished (there should be an entry in BOMparmreportfinish table), then only it will come to inventjournaltrans table, after that only we can post . will your code help in posting a BOM journal in Ax2009
Thanks! I'm using gl00mie's example, but your blog entry is very helpfull.
Great post! By the way, do you know what is the main difference between axapta and dynamics ax? Is it just about the name?
Good luck writing your blog, you're doing great!
You are making a mistake.. just dig deeper and write a simpler code as possible otherwise it will get confusing.
Great post! By the way, do you know what is the main difference between axapta and dynamics CRM? Is it just about the name?
Good luck writing your blog, you're doing great!
Post a Comment