Calling methods on a caller form
This is actually something small but it comes in handy from time to time !
Due to the poor design on some form I have to make changes to, I needed this thing here. I replaced a button on the form with code behind it (yes, business logic behind a button is a BAD practice !) by a MenuItemButton. The only problem was that the form had some objects (f.e. a ledgerJournalEngine object, …) that needed to be available in the class behind it…
Now, this is what I did to get the ledgerJournalEngine object from the caller form and pass it to the class I was calling :
// Get the caller form CIMVendTransInvoicePool to get the ledgerjournalengine object if(ClassIdGet(_args.caller()) == ClassNum(SysSetupFormrun) && (setupFormRun.name() == formStr(CIMVendTransInvoicePool))) { if (formHasMethod(_args.caller(), identifierStr(parmLedgerJournalEngine))) { ledgerJournalEngine = _args.caller().parmLedgerJournalEngine(); DAXCancelRegisteredInvoice.parmLedgerJournalEngine(ledgerJournalEngine); } }
Handy indeed!
Off course, this could also be done by using an event like method.
To check this out, see my other post here :
(http://www.ksaelen.be/wordpresses/dynamicsaxblog/2010/09/event-handling-in-x/)