We start out in the PurchTable form where we, by clicking a button, calls a class with the help of a menu item. The menu item has been given the datasource PurchTable.
The called class updates the record that was selected in the PurchTable, but when this is done the user cannot see the changes without pressing F5 or restarting the form completely. The method FO_doRefresh() does a refresh on the PurchTable Form.
In the called class we can easily get access to the caller object, and in this case we want to check if the caller is PurchTable and if the caller has the method FO_doRefresh(). If this is true, we will run the method to refresh the PurchTable form.
The following code should be placed in the class after all the updates is completed.
if(ClassIdGet(args.caller()) == ClassNum(SysSetupFormrun) && args.record().tableId == tableNum(PurchTable)) { if (formHasMethod(args.caller(), identifierStr(FO_doRefresh))) { args.caller().FO_doRefresh(); } } |
The same principle applies to called forms and reports. The method FO_doRefresh on the PurchTable form contains the following code:
1 2 3 4 5 6 7 8 | void FO_doRefresh() { ; purchTable_ds.reread(); purchTable_ds.refresh(); } |
Last 5 posts in Development
- No valid document identified from the entity key - April 9th, 2010
- Using Regular Expressions in Dynamics AX - October 2nd, 2009
- Create class and methods in x++ - December 22nd, 2008
- Simple field lookup in form - October 13th, 2008
- Get your Intercompany CustAccount - September 29th, 2008
Personally I prefer doing everything in the class like this:
if (args.record().isFormDataSource())
{
args.record().dataSource().refresh();
}
That way all the code is in 1 object and you avoid reflection to check if a method exists.
You are of course correct, I guess my example using a method that only refreshes the caller object might not have been the best one. But I think it’s useful to know how to run methods on the caller object, whatever they might do, create, delete or refresh. It’s also useful to know how to differentiate between callers, in case the class, form or report may have different ones.
I like to looks of you blog by the way. I’m going to take a closer look when I get the time. Looks very ambitious and well structured.
I really don’t know why the first part of my text is in bold text, it’s not supposed to be, looks a bit like I’m yelling at you. 🙂
Thanks for your feedback, always appreciated!