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)

How to passing the the form control value from child form to parent form

(0) ShareShare
ReportReport
Posted on by

Dear all, 

I has some trouble with the passing value between two form.

I have form parent: formA, child form: formB.

From formA, I click on a button to open formB (dont pass anything from formA to formB), and in formB, I do something (text something into stringedit control for an example) and I want to pass the this text(in stringedit control) to formA.

How can I do, please give me some ideal.

Thanks,

DatMC

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Abhishek_mishra Profile Picture
    405 on at

    You can achieve this by accessing caller object in Form B.

    In FormB,  get the caller object like below:

    FormRun caller;

    // Get caller form run.

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

    // Lets suppose there is a stringEDT control named "A" in form A.

    // In form B, you have a control named "B" from which value will be passed to "A"

    // Get that control reference like below

    FormStringControl fcs;

    fcs = caller.control(caller.controlId("A"));

    fcs.text(B.valueStr());

  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Fortunately AX 7 offers a nice object-oriented, statically-typed way how to do it.

    Create an interface, e.g. IValueReceiver, with the operation you need. You want to pass a text value, so you need a method that will accept a string parameter.

    Such as:

    interface IValueReceiver
    {
        void ReceiveText(str _s){}
    }

    Let FormA implement the interface and add any logic you need to happen when you get the value.

    In FormB, get the caller object, cast it to the interface and call the operation:

    IValueReceiver receiver = this.args().caller() as IValueReceiver();
    if (receiver)
    {
        receiver.receiveText("Text from your control");
    }

    This keeps the two forms clearly separate, without exposing any implementation details such as control names, and it gives you compile-time control and IntelliSense.

    A simpler solution may be passing an object through args.parmObject(), casting it to a specific type (class or interface) and setting the value there. Because both forms share the same object, they can use it to exchange information.

  • Community Member Profile Picture
    on at

    thanks Abhishek_mishra,

    but where I can put these code, I put caller in init() method, and

    FormStringControl fcs;

    fcs = caller.control(caller.controlId("A"));

    fcs.text(B.valueStr());

    in the closeok() method but not effect.

  • Community Member Profile Picture
    on at

    Thanks Martin, but where I can put the code in formB (in init(), or run() or closeOK() ...)

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

    It depends on when you want to execute the action. init() and run() run before users can put anything into your StringEdit control, so it doesn't sound like a good choice.

  • Suggested answer
    Abhishek_mishra Profile Picture
    405 on at

    CloseOk method is called only when form is closed with a command button of command type "OK".

    Try putting below code in close method of form:

    FormStringControl fcs;

    fcs = caller.control(caller.controlId("A"));

    fcs.text(B.valueStr());

  • Community Member Profile Picture
    on at

    Dear Abhishek_mishra,

    I get the error "Formrun object not initialized" but I can not fix, can you help me please.

  • Abhishek_mishra Profile Picture
    405 on at

    How are you calling Child form(Form B), using menu item?

  • Community Member Profile Picture
    on at

    I use ClassFactory.formRunClass(args) method to calling formB

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Use a menu item, if you can.

    Otherwise you have to fill the caller by yourself: args.caller(element).

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans