AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.02.2008, 17:40   #1  
Blog bot is offline
Blog bot
Участник
 
25,626 / 848 (80) +++++++
Регистрация: 28.10.2006
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);
        }
}
First of all we need to get rid of journalForm.
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;
        }
}
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:

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
Finally, we are ready to write our remarkable job:

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
Источник: http://rusgon.blogspot.com/2008/02/p...al-from-x.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
inventjournal, программно, разноска

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Ruslan Goncharov: A few words about sorting codes Blog bot DAX Blogs 0 18.02.2009 21:05
Ruslan Goncharov: From Microsoft Dynamics AX Programming newsgroup tricks Blog bot DAX Blogs 0 24.05.2008 00:08
Ruslan Goncharov: Dynamic enabled() property for StringEdit and arrows Blog bot DAX Blogs 0 18.04.2008 20:05
Вопрос про Demand Planner slava09 DAX: Функционал 4 25.09.2006 11:43
Говорят вышел SP2 для Axapta 3. Кто нибуть что знает на эту тему? soin DAX: Прочие вопросы 10 13.10.2003 10:43

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 08:45.