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 :
Microsoft Dynamics AX (Archived)

Passing value between forms

(0) ShareShare
ReportReport
Posted on by

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

  • Suggested answer
    Martin Dráb Profile Picture
    241,635 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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();

       }

  • Martin Dráb Profile Picture
    241,635 Most Valuable Professional on at

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

  • Martin Dráb Profile Picture
    241,635 Most Valuable Professional on at

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

  • Miguel Zuniga Profile Picture
    272 on at

    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
    241,635 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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
    241,635 Most Valuable Professional on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Prashant Singh Profile Picture

Prashant Singh 2

#1
nmaenpaa Profile Picture

nmaenpaa 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans