Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

init method of the target form is called before the onclicked event handler of the menu item thats opening the form

(0) ShareShare
ReportReport
Posted on by

hi, 

i have 2 forms, and i need to select some records from form A and click on a display menu item for form B to open. at the same time i need to pass those selected records to form B. for the display menu item i wrote a onclicked event handler and accessed the records. In the form init method of form B, i'm fetching the passed records.
the problem is that, the init method is being called before the onclicked event handler which is resulting in the selected record not being passed to form B

*This post is locked for comments

  • Suggested answer
    Akash Solanki Profile Picture
    Akash Solanki 2 on at
    init method of the target form is called before the onclicked event handler of the menu item thats opening the form
     1) Just Make a Runnable class which must have a main Method taking (Args _args) as arguments.
    2)Take the suitable arguments from _args.record() like in case of mine , it was table buffer( say ABC abc)
    3) Pass that buffer in args.record()   
                    
    Args args;
    FormRun formRun;
    ;
    super();
    args = new args(formstr(Name of target form)); // sending Args(record) to FormB
    args.record(abc);
    formrun = classfactory.formrunclass(args);
    formrun.init();---- invoking the init method of target form via code.
    formrun.run();
    formrun.wait();
    formrun.detach();
    
    4)One thing , remove the display menu item button. Use Action menu item button with attached Runnable class having this code in it
    5) As the action menu item button will call the main method of the Runnable class
     
     
     
    Akash Solanki
    (akashkumar.solanki@gmail.com)
  • faheem Ahmed Profile Picture
    faheem Ahmed 450 on at
    RE: init method of the target form is called before the onclicked event handler of the menu item thats opening the form

    1: stackoverflow.com/.../how-to-pass-argument-from-one-form-to-another-form-in-ax-2012

    2: https://erpdax.wordpress.com/2014/09/17/passing-args-from-one-form-to-another-form-in-dynamics-ax-2012/

    P.S use second approach if you are following 1st link.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,432 Most Valuable Professional on at
    RE: init method of the target form is called before the onclicked event handler of the menu item thats opening the form

    You could do it, but it would mean lot of coding to get worse result.

    Forget opening the form from code, it's what menu items are for; they fill in parameters, apply security and so on.

    In init() method of the target form, create an instance of MultiSelectionHelper (e.g. MultiSelectionHelper::createFromCaller(this.args.caller()) and iterate selected records through it.

  • RE: init method of the target form is called before the onclicked event handler of the menu item thats opening the form

    so for the event handler i have used the container to store all the rec ids of the selected records and then coverting it into a string and using args.parm(multistring);

    and running either of the below pieces of code:

    1.)mf                                      =   new MenuFunction(identifierStr(HSIFSSICheckReleasedDate), MenuItemType::Display);

           mf.run(args);

    2.)    formrun = classfactory.formrunclass(args);

           formrun.init();

           formrun.run();

           formrun.wait();

           bankChequeTable_ds.executeQuery();

    martin can you elaborate on the solution you were suggesting.

  • RE: init method of the target form is called before the onclicked event handler of the menu item thats opening the form

    i had specified that but it still dint work.

  • Martin Dráb Profile Picture
    Martin Dráb 231,432 Most Valuable Professional on at
    RE: init method of the target form is called before the onclicked event handler of the menu item thats opening the form

    I do see either why you want to put your logic to the event handler and how you would communicate with the form opened by the menu item. It doesn't look as a feasible design to time.

    What logic do you have there? Why don't you run it on initialization of the target form?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans