Question Status

Suggested Answer
Dynamics AX User asked a question on 17 May 2013 12:46 AM

I have scenario I have a parent form which has a method M. If user clicks a button on Parent it opens a child form.In the child form if the user click 'ok' button i need to call a public method in parent form.Ppl around here are suggesting to use form run object which didnt wrk

i used two appoaches

1. {

object formrunobj;

formrunobj=args.caller();

formrunobj.M(); 

}

this approach didn't work.

2.I tried  to pass a string value args.parm() to parent form from child and basing on the string I am tried to run the method with if condition .It didn't work.

Please suggest me any ideas.If possible code example .Thanks in Advance.

Reply
Suggested Answer
Kamalakannan Elangovan responded on 20 May 2013 3:44 AM

In addition to what siva says, Please make sure if it is a command button or menu item button that invokes the child form. If it is a command button you may want to construct the args object through code by overriding the clicked method of the command button.

- Kamal

 MyBlog | Twitter | LinkedIn

Reply
Martin Dráb responded on 17 May 2013 1:08 AM

"Didn't work" means "I do it wrong", but you didn't give us enough information about the problem. What exactly happened?

If the method can't be invoked, check how you get the args variable. Then verify that args.caller() returns the right object. Then ensure yourself that M() exists and has no parameters.

You may also look at Dynamic method dispatch in X++.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
Sivananth Subramaniam responded on 17 May 2013 2:15 AM

Could you please try the below code

In the Parent form

void parentMethod()

{

   //some code here

}

In the child form, you can do this

void callParentMethod()

{

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

   if (callerForm)

   {

       if (callerForm.name() == formstr(<form name>))

       {

           callerForm.parentMethod();

       }

   }

}

Regards,

Siva

Reply
Suggested Answer
Kamalakannan Elangovan responded on 20 May 2013 3:44 AM

In addition to what siva says, Please make sure if it is a command button or menu item button that invokes the child form. If it is a command button you may want to construct the args object through code by overriding the clicked method of the command button.

- Kamal

 MyBlog | Twitter | LinkedIn

Reply
Dynamics AX User responded on 20 May 2013 11:50 PM

Yes ,Its a command button and I overrode clicked method ,and in the method I need to call a public method in the  parent form.But,when I am trying to use args.caller(). I am seeing the caller class instead of the parent form.So,I am unable to access the public method in parent form from child'd override method.I am wondering if there is an alternate approach to call parent forms public method.

Reply
Dynamics AX User responded on 20 May 2013 11:51 PM

I apologize for my unclear question....

Reply
Sivananth Subramaniam responded on 21 May 2013 2:04 AM

Try the below line of code.It should work as you expected.

callerForm.owner().parentMethod();

Reply
Martin Dráb responded on 30 May 2013 12:46 AM

If the caller class has a reference to the parent form, simply call a method in the class from your child form and let the class to pass the message to the form.

If you don't have any reference to the parent form, you simply can't call its methods - you have to change the implementation first to get the reference.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply