24.02.2008, 17:40 | #1 |
Участник
|
Ruslan Goncharov: Posting InventJournal from X++
Источник: http://rusgon.blogspot.com/2008/02/p...al-from-x.html
============== Once I was faced the problem to post InventJournal from code. 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. X++: static void main(Args args) { InventJournalCheckPost journalCheckPost; journalForm journalForm; ; journalForm = journalForm::fromArgs(args); journalCheckPost = InventJournalCheckPost::newFromForm(args,journalForm); journalForm.runbaseMainStart(); if (!journalCheckPost.PROMPT()) { 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. X++: 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; } } 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: X++: // 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 X++: 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
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
Теги |
inventjournal, программно, разноска |
|
|