Thursday, September 17, 2009

How to call a method from a caller form

Introduction: Lots of time we need a method from calling object to be run when the code is running from called object for example if we have a class called by a form object and we need some values in class from a caller form object then we can get those values by calling a method from a caller from in a class.

Let’s see a real life example in dynamics which shows how we can do this.
  • Open “ProjInvoiceProposal” form in AOT and then you will see a button as “Create invoice” in the right side.
  • Actually this MenuItemButton is calling “ProjInvoiceChoose” class.
  • Let’s go to class node and search “ProjInvoiceChoose” class, once you get the class just right click and select edit option this will open all its methods.
  • Go to “Main” method of the class and you will see some code similar to given below.
if (args && args.caller())
{
projInvoiceProjId = args.caller().projInvoiceProjId();
projId = args.caller().projId();
}
if (args.caller() && args.caller().callerDataRecord())
{
argsTrans.record(args.caller().callerDataRecord());
transIdList = ProjInvoiceChoose::createTransIdList(argsTrans);
}
  • Here you can see the statement like “args.caller().projInvoiceProjId();” In this args.caller() refer to the calling object that is “ProjInvoiceProposal” form in this case and "projInvoiceProjId()" is a method which is created in caller form and called in “ProjInvoiceChoose” class.
  • Similarly two more methods called by args.caller() that is “projId()” and “callerDataRecord()”.
Note: You can check the “ProjInvoiceProposal” form and in the method node of the form you will find these methods.

Summery: So this is how we can easily call methods from calling object and use it as per our requirement.

No comments:

Post a Comment