web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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 230
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
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,763 Most Valuable Professional on at
    Have you added some dialog on your own or are you actually talking about the standard RunBase dialog executed by standard code in ProdJournalCheckPost::main()?
     
    If you mean the standard dialog, you can find this information in dialogCanceled variable. Don't forget it's an instance variable. Then you can use "if" statement to run your code only if dialogCanceled is true.
  • CU21091228-0 Profile Picture
    230 on at
    It's standard dialog which is calling from ProdJournalCheckPost::main()
  • Martin Dráb Profile Picture
    238,763 Most Valuable Professional on at
    OK, so my previous reply applies to your situation.
  • CU21091228-0 Profile Picture
    230 on at
    Hi Martin,
     
    I have use below code.
    boolean dialogCanceled;
    
    If (dialogCanceled == true)
    {
    }
    It's not working.
     
    please suggest how to use dialogCanceled in my extension class.
  • Martin Dráb Profile Picture
    238,763 Most Valuable Professional on at
    Well, your solution has two big problems:
     
    1) It ignores my suggestion. It has nothing to do with the variable that the RunBase framework sets when the dialog gets cancelled.
    2) It doesn't do anything and it can't ever do. The condition is "if never", because the value of your variable is always false.
     
    How did you expect this code to work?
  • CU21091228-0 Profile Picture
    230 on at
    I am not able to get dialogCanceled value in my extension class.
     
    Please guide me how to get dialogCanceled value in my extension class.
  • Martin Dráb Profile Picture
    238,763 Most Valuable Professional on at
    Please tell us more about your problem then just "I am not able to get". Also, if you want us to help you with your code, a good idea would be sharing your code with us.
  • CU21091228-0 Profile Picture
    230 on at
    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.
  • Martin Dráb Profile Picture
    238,763 Most Valuable Professional on at
    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
    230 on at
    Could you please share some code for example.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans