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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Passing Values between 2 Forms

(0) ShareShare
ReportReport
Posted on by 1,385

 Hello Everyone,

If we have 2 forms FormA & FormB and we are calling FormB from FormA using MenuItemButton, at the same time we need to pass value to FormB from FormA how can we accomplish this?  What I need is to create public variable on FormB and update the value of that variable from FormA or if there is another way this is great.

I know we have examples on how to pass values between 2 forms using X++ using Args and FormRun but the issue here is I am using MenuItemButton to display a form (No coding)

 Thanks

*This post is locked for comments

I have the same question (0)
  • Ivan (Vanya) Kashperuk Profile Picture
    on at

    Well, you can always get access to FormA from FormB, using args.caller(). You can access its datasources, and call its methods. Now all you need is to create a method on FormA, that will return your value, and access it through element.args().caller() from FormB.

    This way you won't have to change any code for calling FormB (just use the menu button).

  • Abdallah Zein Al Abdin Profile Picture
    1,385 on at

     Thanks a million Ivan it worked.  I created accessor method to retrieve the value I want on FormA and Called it from FormB

  • mstrillian Profile Picture
    282 on at

    I created accessor methods on FormA and could not access them when FormB was called. Can you give some more information here? For example, what, if anything did you set equal to your element.args().caller() method in the init of FormB?

    When I try to do element.args().caller().parmData(), the parmData() is not accessible. I made it a public method. What am I doing wrong?

  • Ivan (Vanya) Kashperuk Profile Picture
    on at

    You should first assign the element.args().caller() to a variable of type object;

    that way you will avoid the compile-time validation for method existense.

    object formRunCaller;

    ;

    formRunCaller = element.args().caller();

    formRunCaller.parmData()

  • Abdallah Zein Al Abdin Profile Picture
    1,385 on at

     Thanks Ivan,  you answered the question I want to add a little thing here.  If you created a method on FormA called MethodA() and you need to call it from FormB you can access it this way:

    object formRunCaller;

    ;

    formRunCaller = element.args().caller();

    formRunCaller.MethodA()

     

  • mstrillian Profile Picture
    282 on at

    Thanks! This is great to know how to access a method on your parent form. My real issue was that I wanted access to the datasource from the previous form. I thought I had to create a parm method on the previous form to return the value of those fields to me. This is what I ended up doing though:

    In the init() method of FormB, I put the following code -

    vendTable    vendTableFromForm;
    ;

    super();

    if(element.args().record())
        {
            vendTableFromForm = element.args().record();
            FormBFilteringField = vendTableFromForm.FormAField;
        }

    It seems to be working. Let me know if there's any reason you don't think that would work or if there is a "better" way to do this.


    Thanks for your help!

  • Jamila ALI Profile Picture
    5 on at

    Hi,

    It works when you have two forms, but what about lookup form? I mean if you call a lookup form from a form with a "lookup" method on the form data source field.

  • Johnny Profile Picture
    6,478 on at

    Hello,

    I have done the same as discussed.

    I have added one menuitembuton in salestable form and in the destination form's initValue method I'm doing :

    formRunCaller = element.args().caller();
        if (formRunCaller.name() == formStr(SalesTable))
        {
            .....
        }

    If I open the form from salestable it is working properly but if I open it from AOT it says:

    "Object object not initialised" which comes from the "if" line

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    If you open the form from AOT, there is no caller and the formRunCaller variable in null. Then you try to call a method (name()), which obviously must fail on null.

  • Suggested answer
    Mehul Thacker Profile Picture
    165 on at

    Hi Abdallah,

    According to me there is only option left if you don't wan to pass value by coding, which is to use following three menu item properties if it fits your requirement. To pass different values you can create different menu items.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans