-1

I want refresh a form from a class. I want the refreh after a insert() statemant. Is here a better solution for this problem.

Here is my code:

try {
    do {  
        row++;  
        this.readRow(row, cells);  
        ttsbegin;  
        this.insert();  
        ttscommit;  
        type = cells.item(row+1, 1).value().variantType();  
     }  
     while (type != COMVariantType::VT_EMPTY);  
                         <--------

After the while the insert is finished and at this position where I will the refresh.

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • I had to keep my answer quite generic as I could not infer the architecture of your code based on the small snippet you posted. If my answer is too generic then please post more code (e.g. how you create and invoke your class from the form and what table etc. you use) – DAXaholic Aug 04 '16 at 10:18
  • I have a main method (run) in this method how you see i calls the readRow and insert method. I call the run method by a button on the form. The button starts the import of the excel sheet. – Felix Schneider Aug 04 '16 at 10:22

1 Answers1

2

Usually you would pass a reference of the form's data source you want to refresh to your class and then call research on it to refresh it so that your newly inserted records appear.

Alternatively, although IMHO not that clean, is to pass a buffer of that form's data source to your class and then (maybe after checking via isFormDataSource) access and refresh the data source via the buffer's dataSource method.

A third way would be to implement a dedicated method on your form solely for the purpose of refreshing the data source as described above. When creating the instance of your class you then pass a reference to your form so that you can call that method when needed.

Update: To see how to call a method defined on a form from a class see the class Tutorial_Apply and form Tutorial_Form_Apply which shows how to call the method applyText which is implemented on the form. Likewise, you could define a method refreshData which calls research on your data source.

DAXaholic
  • 33,312
  • 6
  • 76
  • 74
  • I think the last way is the best way. But i'am new to AX so i have no idea to make this. – Felix Schneider Aug 04 '16 at 10:24
  • Need my form a special method to refresh ? At the moment my form has two method init and classDeclaration. – Felix Schneider Aug 04 '16 at 11:39
  • Well it needs the method you want to call from the class, e.g. let's call it refreshData. Then in it you would call research on the form's data source. As I mentioned I could be more specific if you show more of your code – DAXaholic Aug 04 '16 at 11:43
  • I know in my class i need a method (refreshForm) with `salesTableImport_ds.research();` correct ? salesTableImport is my table where i insert records. What code part do you want do get more informations ? Thanks for your help. – Felix Schneider Aug 04 '16 at 11:47
  • If you are going to call a form method from a class via the `Object` class, you should validate the method exists by calling something like this `if (SysTest::hasMethod(object, identifierStr(YourFormMethodName)))` otherwise, you can have run-time errors. – Alex Kwitny Aug 04 '16 at 17:36
  • Well if you were to implement the 3rd option (call method on form) then you should rather create the method 'refreshForm' on the form and call salesTableImport_DS.research() within it. When creating your instance of your class you pass a reference of the form to it and then call it at your desired place. Of course to make the class reusable without that form, you should check via 'formHasMethod' whether the form implements the method 'refreshForm' before calling it as suggested by Alex Kwitny – DAXaholic Aug 05 '16 at 13:52
  • No problem this is not so important at the moment. – Felix Schneider Aug 11 '16 at 07:21