Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Extension class should not call if i click on cancel button from dialog box

(0) ShareShare
ReportReport
Posted on by 171
Hi Team,
 
I am following the below link.
 
 
I have extend the ProdJournalCheckPost class.
 
Production control -> PickingList -> Click on Post button.
 
In case if i click on post button one dialog box has open, if i click on cancel button from dialog box my code is calling which i wrote in ProdJournalCheckPost_Extension.main();
 
I want if i click on cancel button from dialog box my code should not call which i wrote in ProdJournalCheckPost_Extension.main();
 
Regards,
Mohan
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Extension class should not call if i click on cancel button from dialog box
    As I mentioned, many things happen after clicking the button and where you place your has enormous impact on business logic. Therefore saying just "somewhere after clicking the button" is not useful. It's not enough information to make a decision. And choosing one of the available places randomly without consider business requirements is a bad idea; it's not how you should makes changes to some company's mission-critical software.
     
    Of course that code of parent classes will be called. That shouldn't be a surprise if you have some idea about object-oriented programming or you payed attention to method and variables I mentioned before, because they're too defined in parent classes.
     
    Therefore yes, run() method is one of hundred methods called at some point after clicking the button. But is the right method to extend? Well, it depends on the business requirements, which you don't know, so we can't make any decision for sure. But I think it's not the right one. If you want your logic at a place where run() executes, you likely don't want it just after run(), but inside the transaction and the logging scope. Such as in runEnd() method.
     
    If you need to have extra data there, you'll need to put them to something serializable (e.g. a Set of RecIds), store them in an instance variable of ProdJournalCheckPost and extrend pack() and unpack() methods to deal with serialization.
     
    Personally, I'm not convinced that you should extend ProdJournalCheckPost class at all. I think you should use composition instead: to create a new class that will iterate selected records and call ProdJournalCheckPost for each of them. But I can only guess if you can't tell us what business problem you're trying to solve. You focus on implementations details,but maybe your overall design isn't correct. It wouldn't be surprising - the fact that you're struggling with things like using a variable shows that you aren't an experienced developer, so you it's quite possible that you don't know how to design the whole thing. So maybe you should start in a different way: collect and understand business requirements, share it with us and ask as for help with the design. And start coding only when you have an idea about what you're trying to implement and what will be the approach to do it.
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    Extension class should not call if i click on cancel button from dialog box
    My requirement is if i click on post button and click on ok button.
     
    First it will check the validation in case for selected records if there are validation error it should not be post and if no validation error it will get post.
     
    I have found the another class which will always be call after click on okay button from dialog box which is JournalCheckPost.run().
     
    But my query is how i will get the _args() value in  JournalCheckPost.run().
     
    Because i can see JournalCheckPost.run() will get call if i click on Validation button and Post button from Production control -> PickingList.
     
    Below is my current code which i have wrote in ProdJournalCheckPost::main()
     
    journalForm      = JournalForm::fromArgs(_args);
    prodJournalTable = journalForm.journalTableData().journalTable();
    
    
    if (prodJournalTable.JournalType ==  ProdJournalType::Picklist && _args.menuItemName() == menuItemActionStr(ProdJournalPost))
    {
       _args.parmEnum(JournalCheckPostType::Check);
    }
    
    next main(_args);
    
    if (prodJournalTable.JournalType ==  ProdJournalType::Picklist && _args.menuItemName() == menuItemActionStr(ProdJournalPost))
    {
    }
    Here i am using  _args.menuItemName() == menuItemActionStr(ProdJournalPost)), get the menuItemName from _args and it should match with ProdJournalPost menuItem.
     
    Please let me know how i will _args in JournalCheckPost.run(), so i can extend the JournalCheckPost.run() and write the code
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Extension class should not call if i click on cancel button from dialog box
    Aha, if you want if the dialog is confirmed, that's probably even easier. But before you can write code, you need to think about when the logic should execute. For example, imagine that you put some values in the dialog, configure it to run in batch and confirm the dialog. When you do you want your logic to run? During the standard posting, in the same transaction? After the posting, in a separate transaction (therefore a failure in your code won't rollback the standard posting)? Or somewhere else?
     
    When you understand what you want to achieve, you'll look at the class and find a place meeting your requirements.
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    Extension class should not call if i click on cancel button from dialog box
    Seems Approach 3 will not work because as per my requirement if i click on cancel button my customize logic should not call, it should call if i click only okay button.
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Extension class should not call if i click on cancel button from dialog box
    Approach 1: You need to look into the class you want to extend and think about when you want to execute your code. You see main() method, but you can open it and look at what it does. It's clear that your extension must be after closing the dialog, which happens in prompt(), therefore this is one of possible places.
     
    Approach 3: I can't tell you what logic you want to run. I assume you want what you currently have in ProdJournalCheckPost_Extension::main().
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    Extension class should not call if i click on cancel button from dialog box
    Approach 1:
     
    I can see only ProdJournalCheckPost::main() method is call while click on the post button, in this case which instance method should i extend of ProdJournalCheckPost class?
     
    Approach 3:
     
    ProdJournalCheckPost::main() calls runbaseMainCancel() method while click on the cancel button from dialog box, what logic should i write in runbaseMainCancel() method?
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Extension class should not call if i click on cancel button from dialog box
    Which of the three approaches you're trying to use, what is your current problem and what the example you're asking for should show?
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    Extension class should not call if i click on cancel button from dialog box
    Could you please share some code for example.
  • Martin Dráb Profile Picture
    Martin Dráb 230,846 Most Valuable Professional on at
    Extension class should not call if i click on cancel button from dialog box
    I warned you that the variable is an instance one and the error messages tells you the same thing, when you tried to use it as a static one anyway. To access an instance variable, you need an object. And not just a random object, you need the one that opened the dialog and now holds the information about the result.
     
    Unfortunately, it's impossible to do in your current code, because the object (journalCheckPost) is both created and destroyed in next main(_args). Accessing it from your main() method is impossible. You have a few options:
    1. Instead of extending the static method main(), extend an instance method of ProdJournalCheckPost class.
    2. Instead of calling ProdJournalCheckPost::main() (through a menu item), create a new class for your purpose and use it instead of ProdJournalCheckPost. There call the same code as in ProdJournalCheckPost::main(), but then you have access to the object. Personally, I would prefer the previous approach, because it's simpler and you don't have to deal with security setup.
    3. I've noticed that ProdJournalCheckPost::main() calls runbaseMainCancel() method of the caller JournalForm object. Maybe you could put your logic there. (JournalForm is an abstract class, you'd need to extend the concrete child used in your scenario.)
     
    If you have no idea about object-oriented programming and terms like objects and instance variables don't make sense to you, you should definitely spend some time learning the basics, otherwise you'll keep struggling with such things.
  • CU21091228-0 Profile Picture
    CU21091228-0 171 on at
    Extension class should not call if i click on cancel button from dialog box
    Below code i am using.
     
    [ExtensionOf(classStr(ProdJournalCheckPost))]
    final class ProdJournalCheckPost_Extension
    {
        public static void main(Args _args)
        {
            next main(_args);
            
            JournalForm journalForm;
            ProdJournalCheckPost journalCheckPost;
            Boolean   ok;
            
            #ISOCountryRegionCodes
                      
            try
            {
                if (_args.dataset() != tableNum(prodJournalTable))
                {
                    return;
                }
                
                FormDataSource prodJournalTable_ds = _args.callerFormControl().formRun().dataSource();
                Object caller = _args.caller();
                
                MultiSelectionHelper helper = MultiSelectionHelper::createFromCaller(caller);
                helper.createQueryRanges(prodJournalTable_ds.queryBuildDataSource(), fieldStr(ProdJournalTable, RecId));
                
                ProdJournalTable prodJournalTable = helper.getFirst();
                while (prodJournalTable)
                {
                    _args.parmEnum(JournalCheckPostType::Check);
                    _args.record(prodJournalTable);
    
                    journalForm = JournalForm::fromArgs(_args);
                    journalCheckPost = ProdJournalCheckPost::newFromForm(_args, journalForm);
                    journalForm.runbaseMainStart();
    
                    prodJournalTable = helper.getNext();
                    journalCheckPost.preRun();
                    journalCheckPost.runOperation();
                    
                    journalForm.runbaseMainEnd(journalCheckPost, false);
                }
            }
            catch (Exception::Error)
            {
                if (journalForm)
                {
                    journalForm.runbaseMainEnd(journalCheckPost, true);
                }
            }    
        }
    }
     
    Before try i am using below code
    if (dialogCanceled  == true)
    {
    }
     
    Following error i am getting
    dialogCanceled  is not accessible from static method main.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans