Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Passing value between forms

Posted on by Microsoft Employee

Dear experts,

I'm new to x++ & ax world, i have this forms :

8561.form.PNG

I made this forms because i'm learning how to pass values between forms. From many sources i have read, i need to override clicked method in parent form's ok button, and then place code inside init() in child form. But, everytime i clicked ok, form B doesn't show me anything just empty. Can anyone help me solve this? Thanks Here's my code :

Form A :

void clicked(){
    FormRun formRun;
    Args args;
    super();
    args = new args();
    args.parm(ATable_A.text());
    args.name(formStr(bform));
    formRun=ClassFactory.formRunClass(args);
    formrun.init();
    formrun.run();
    //formrun.wait();
    //formrun.detach();
    atable_ds.refresh();
    atable_ds.executeQuery();
}

Form B :

public void init(){
    str any;
    
    super();
    
    if(element.args()){
        any = element.args().parm();
        BTable_b.text(any); //why the stringedit or textfield still empty????????????
    }}

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    RE: Passing value between forms

    Tharindu, why exactly does your code have a case when it's possible not to call super() of init()? The form wouldn't work at all in such a case, which is a serious bug.

    Also, as I mentioned above, setting a value directly to the control wouldn't work if it's bound to a datasource.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Passing value between forms

    public void init( )

    {
        str 50 any;    
       
        if(element.args()){

            any = element.args().parm();  // get string parameter

            super();    

            BTable_b.text(any); //use any data for your code;

        }

    }

    This should work for you. You have to initialize number of characters to the string.

  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    RE: Passing value between forms

    If you debug the code, you'll (most likely) see that you get an error at the second line.

    You didn't tell us where you're using your code, but it seems you try to work with BTable_b object before it was created. Also, if the control is bound to a datasource, you should work with the DS field (also after it gets initialized) instead of with the individual control.

  • Miguel Zuniga Profile Picture
    Miguel Zuniga 270 on at
    RE: Passing value between forms

    Hi Martin, I've done the same thing of what he is doing I am getting a value however everytime I run this

           any = element.args().parm();

           BTable_b.text(any);

    the form this errors shows up "FormStringControl object not initialized".

  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    RE: Passing value between forms

    For reference, the user's created another thread about a similar same topic.

  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    RE: Passing value between forms

    The method returns an object - the source form. You can save it a variable, call its method etc. - just as with any other object.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Passing value between forms

    Hi Martin,

    Thanks for your answer, Martin. I'm trying to find how to use this element.args().caller() but i haven't found the proper answer.  Did i use it almost right?

       super();

       if(element.args())

       {

           element.args().caller();

       }

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    RE: Passing value between forms

    First of all, always open forms through menu items; do it in code only if there is no other way. Menu items have useful properties such as label and help text, you can configure permissions for menu items etc.

    One option is actively pushing values to an Args object, but that's not the only way. Some values are already put there by AX, especially the active record (which is the most common way how to pass data between forms). You can also get a reference to the caller form (by calling element.args().caller() in the target form) and use its methods. Therefore you often don't have to write any code at all in the source 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,188 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans