FormObservable is indispensable for edit/display methods on form / refresh data automatically for display/edit method

 

Hello Everyone,
I hope you all doing well!

 today I am going to share about one of significant thing that we all should know to handle edit/display form and that is "FormObservable".
Did you already tried this interesting feature in D365 ? if not , then we should.

Here , we have some set of rules :-
a) If display/edit method should be refreshed on specific event , for an instance it should refreshed on some button click or method call , to handle this we can use " FormObservableLink" class. This class is useful for refreshing display and edit methods by creating instance variable of FormObservableLink type in a form init(). This class has two vital methods :-
  • markChanged() - This method is used to notify the form that it should execute the display/edit methods. In other words, when refresh is required , calling markChanged() method of FormObservableLink cause system to rerun display/edit methods and display new values.
          [Form]
          public class TestForm extends FormRun
         {
               FormObservableLink ObservableLink;
               public void refreshMyDisplayMethod()
              {
                     // Here we trigger a refresh
                    ObservableLink.markChanged();
              }
              public void init()
             {
                   super();
                   ObservableLink = new FormObservableLink();
             }
          }

  • Observe() -  This method receive notification and call it in display/edit methods that you need to refresh on demand.
            [DataSource]
            class TestTable
           {
                  public display Str   myDisplayMethod(TestTable _testTable)
                 {
                           // This says that observableLink will be able to refresh myDisplayMethod()
                           ObservableLink.observe();
                           
                          //  your display method logic
                          ......
                 }
            }

b) If display/edit method depends on another datasource , then you are best off use of dataSource.Observe(). Here, testTable_ds.observe() is used to observe testTable_ds datasource and AX will automatically execute display methods if any record is getting updated , inserted or deleted.

           [DataSource]
            class TestTable
           {
                  public display Str   myDisplayMethod(TestTable _testTable)
                 {
                           testTable_ds.observe();
                           
                          //  your display method logic
                          ......
                 }
            }

 I hope this helps you.

Comments