I have some custom code in PurchTable "Register" menuitem's clicked method, Now I need to run the Register command from code after a buttons function has been perfomed.
My question is that how can I call the Register command from code ?
I see that you're actually trying to execute the clicked() method, but if you want to execute a Menu Item through code, you can do the following:
new MenuFunction(menuItemDisplayStr(MyDisplayMenuItem), MenuItemType::Display).run();
Of course the code above may be changed to execute different kinds of Menu Items, for example, the code below runs an Output Menu Item:
new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output).run();
And if you need any argument on the Menu Item you're trying to execute, you can pass it with the Args class:
Args args = new Args();
args.record(myArgumentRecord);
args.caller(this);
new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output).run(args);
Set the AutoDeclaration
of the Register
button to Yes.
Then it is straightforward to call clicked
:
register.clicked();
It is not advisable to have large bodies of code in form methods.
Reference:
The basic concept of three-tier architecture is that forms should be used only for the presentation tier and hence no other code such as business logic should be there on forms. The code placed on forms also reduces their reusability and the ease of further customization; e.g. if you want to develop an enterprise portal, the code written on forms will have to be written again in classes or table methods, etc., which will make the implementation complex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With