ClearDynaLinks Method

Here is something regarding the form datasource. I have two tables, BikeCustTable and BikeInvoice. The relationship for that two table is link through AccountNum. Assume there are some data in that two tables, please see the following screen.
There are two forms (Form A and Form B), both of the forms require BikeCustTable as datasource. However, in Form B, it require extra datasource, which is BikeInvoice. In Form A, it consists of a grid and a menu item button. The grid datasource is Table A and consists of fields from Table A. Meanwhile, there is a menu item button, calling Form B. For this menu item button, we have to pass the current datasource to form B.
In Form B, there only consist of one grid, and a two datasource (BikeCustTable and BikeInvoice). The BikeCustTable datasource is inner join with BikeInvoice datasource. The grid in Form B consists of fields from two table.
The scenario is like following. When user open the Form A, it display on the screen. It works well and fine. When user click the menu item button, the Form B will be display. However, you will notice the only AccountNum 100 will be display only. Where is AccountNum 101? Why it never appear in Grid?
Imagine I have two forms, Form A and Form B. Both of the forms require BikeCustTable as a datasource. In form B, I have

Here is something regarding the ClearDynaLinks method. Mostly you read many blogs, sites and so on that theoritically explain this method. Moreover, no further explaination or example is being provided. It is hard for new comer to catch up the idea.

Before I explain how that method work, we have to know our “ingredient”. I have two tables, BikeCustTable and BikeInvoice. The relationship for that two table is link through AccountNum. Assume there are some data in that two tables, please see the following screen.

Tables
Tables

After review our “ingredient”, is time for us to prepare our meal. First, we need two forms, Form A and Form B, both of the forms require BikeCustTable as datasource. However, in Form B, it require extra datasource, which is BikeInvoice. Take a glimpse on the screen below.

Datasource for Form A and B.
Datasource for Form A and B.

In Form A, it consists of a grid and a menu item button. The grid datasource is Table A and consists of fields from Table A. Meanwhile, there is a menu item button, calling Form B. For this menu item button, we have to pass the current datasource to form B. See the screen below.

Form A Design

Form A Design

In Form B, there only consist of one grid, and a two datasource (BikeCustTable and BikeInvoice). The BikeCustTable datasource is inner join with BikeInvoice datasource. The grid in Form B consists of fields from two table.

Form B Design

Form B Design

The scenario is like following. When user open the Form A, it display on the screen. It works well and fine. When user click the menu item button, the Form B will be display. However, you will notice the only AccountNum 100 will be display only. Where is AccountNum 101? Why it never appear in Grid?

Running 1

Running 1

Notice when I select AccountNum 101 in Form A, it will cause changes on Form B. In Form B, only records that have the AccountNum 101 will be displayed. Other records will not be displayed.

Running 2

Running 2

Why happen to the program? Why AccountNum 101 not being displayed in Running 1, and why AccountNum 100 not being displayed at Running 2? Notice when I select the record in Form A, it will reflect the changes in Form B. Why this happen? The answer is if same datasource exists in both forms, AX will try to link it together by default. This is the fact.

For disable the link, ClearDynaLinks method can be apply if you don’t want the linking to be carry forward to next form. Please look at the screen below to see the additional code that add under the datasource init method.

Solution

Solution

By add in this.query().dataSourceTable(tablenum(BikeInvoice)).clearDynalinks(); into the BikeInvoice data source init method to disable the linking. Doing so will broke the link and there will be two separate datasource in two forms. Hope after you go through this post, it will help you understand the the ClearDynaLinks method.

Posted in Dynamics AX, Technical Stuffs | Leave a comment

How to pass value from MenuItemButton to a Dialog Class?

Hi everybody, as mentioned in my previos post, I will share the knowledge about dynamics AX on technical/functional perspectives. During your AX development, you will encounter different technical scenario. Although some of the scenario is able to obtain solution, but we still seeking for the best solution.

Overview

 

The lesson I would like to share with you is “How to pass value from MenuItemButton to a Dialog Class”. Imagine a situation you have a MenuItemButton on a form, and the MenuItemButton is calling a MenuItems (Action) and finally call the dialog class. For certain scenario, you would like to pass a value, perhaps a record, from the FORM to the DIALOG class, but you are constraint by the MenuItemButton. Possible to do it? Some of you might suggest you that MACRO can be applied here. However, apart from that, what other solution you can use? 

 

Here, I introduce to cast the caller (mean the form) to ObjectRun type. Below are the steps that teach you how to achieve that.

 

Step 1: Create a dialog class, call it as MyDialogClass and extend from RunBase. In the classDeclaration part, declare a global variable, objRun, type ObjectRun. Please see picture in the galery (Step1.jpg).

Step1

Step2: Declare a method to initialize the objRun create in Step 1. Here, I call it as initObject method with an input parameter Args. Please see Step2.jpg.

void initObject(Args args)
{
objRun = _args.caller();
}

                             void initObject(Args args)

                             {

                                 objRun = _args.caller();

                             }

Step2

Step 3: Overwrite the dialog method. The code are like following. For details, you can refer to Step3.jpg.

                            protected Object dialog()

                           {

                                    DialogRunBase dialog = super();

                                    ;

                                   dialog.addText(“Output: ” + objRun.args().parm());

                                  return dialog;

                         }

Step3

Step 4: Create a main method for the class. The code is like following. Please refer to Step4.jpg as well. After finish the develop the class, please create an MenuItem, with an Action type.

                        public static void main(Args _args)

                       {

                             MyDialogClass dlgCls = new MyDialogClass();

                             dlgCls.initObject(_args);

                              dlgCls.prompt();

                         }

Step4

Step 5:  This is last step. Create a form, here I named it as MyInputForm. In the form, add a StaticText and MenuButtonItem. The StaticText (I named it as Input1) which used for us to enter the value we want to pass to the dialog class. For the details, please refer to Step5.jpg. Remember to associate the MenuButtonItem with the MenuItem create on step 4 in order when you click on the button, it will call the class. For the MenuButtonItem, overwrite the clicked event. The following code should allocate under this method:

                          void clicked()

                          {

                               element.args().parm(input1.valueStr());

                               super();

                          }

Step5

After complete step 5, compile all the code and you can having a test. Enter some of text into the input and click the MenuItemButton, you will able see the your input appear on the dialog. Hope this lesson will benefit you.

Result

Posted in Technical Stuffs | Leave a comment