Sunday 11 September 2011

How to add Search/ Find /Filter functionality to Display method in dynamics AX

Dynamics AX, can retrieve output values by using table field and display method. As we know, usually standard dynamics AX filter functionality is working only for table field. But sometimes we have to do filter functionality for display method too. Below I’m going to explain how to add a filter functionality for Display method.

1.      Here I have added display method (disCustName) to display customer name on the “IND_BusRelation” form. In this form main data source is “smmBusRelTable”.

2.      Change “AutoDeclaration” property from No to Yes of the “disCustName” data field.
3.      Override “context()” method of the “disCustName” data field and add following code.
  
public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;

    selectedMenu = menu.draw();
    switch (selectedMenu)
    {
    case -1: //Filter by field
            break;
    case a:
            ag = new args('SysformSearch');
            fr = new formrun(ag);
            fr.run();
            fr.wait();
//Reading User entered value for filter process
            strtext = fr.design().controlName('FindEdit').valueStr(); 
            if(strtext)
            {
//Creating a query for filter
                q   = smmBusRelTable_ds.query();
                qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
                qb1 = qb1.addDataSource(TableNum(CustTable));
                qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
                qb1.addRange(FieldNum(CustTable,Name)).value(strtext);
                smmBusRelTable_ds.query(Q);
                smmBusRelTable_ds.executeQuery();
            }
            break;

    case b:   // Filter By Selection
            q   = smmBusRelTable_ds.query();
            qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
            qb1 = qb1.addDataSource(TableNum(CustTable));
            qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
            qb1.addRange(FieldNum(CustTable,Name)).value(disCustName.valueStr());
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.executeQuery();
            break;
    case c :   // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(smmBusRelTable));
            qb1.clearLinks();
            qb1.clearRanges();
            smmBusRelTable_ds.query(Q);
            smmBusRelTable_ds.removeFilter();
            break;

    Default:
            break;
    }

}

4.       Run the form and do right Click on Customer Name field.


 

Saturday 8 January 2011

XPO Deployment in Dynamics AX

In Dynamics AX, One of the key methods of deploying new development to the AX environment is XPO Deployment. When modification is moving to the AX environment, we have to make sure to do comparing object process.


Comparing objects can be done either when importing a XPO file or by right-clicking on an object that exists in more than one layer and choosing “Compare” from the Add-Ins menu.

When importing a XPO file,
  • Browse the XPO file & Open it. You can see tree view of all objects which contain in the XPO file.
  • Right click on object which you want to compare and select “Compare”.

Figure 1


  • When you select to compare XPO, the system will display a compare window (Figure 2). When clicking the lookup button for choosing the layer to compare. You might notice that the same layers are listed twice, with one set marked as old layer. The old layer is from the layer files stored in the application’s old folder.

Figure 2



  • The compare window is divided into two panes. In the left side you have the tree view for the object. The right side shows the comparison results for the node selected in the left pane. The comparison results have the colors red and blue. The colors are used in the result to show the differences between the selected layers & XPO. Only nodes where there are differences are shown in the tree. The differences in layer & XPO are identified by color. In the tree a blue or a red checkbox indicates that the node only exist in the layer represented by that color. A two-colored icon indicates that the node is modified in both layer & XPO.

  • In the compare window, lines of code which only exist in one layer are colored with the color representing that layer. A left or right arrow is displayed in the end of a colored line or a colored block of code. By clicking the arrows you can add or remove code to or from the current layer.

Sunday 19 December 2010

Override the event methods on dialog controls in Dynamics AX

In generally most of the Form control events (Modifying Field, Cursor movements, Focusing events, etc...) can override using standard AX method. But in dialog control events are not as straight forward as it is on form controls. Today I’m going to show how we can override Dialog controls events.

Step 1: Create a Class extends by RunBaseBatch class & declare main variables. In my example I have extended by RunBaseBatch Class.

class Test_DialogField extends RunBasebatch
{
    CustAccount     CustId;
    DialogField     dialogCustId;
    DialogField     dialoglName;
    Dialog          dialog;

    #define.CurrentVersion(1)

    #localmacro.CurrentList
        CustId
    #endmacro
}

Step 2: Add Pack() & Unpack() methods. Here I have not written code to store & retrieve stored data. But I added those methods to avoid compiling errors.

public container pack()
{
    return connull();
}

public boolean unpack(container packedClass)
{
    return true;
}

Step 3: Add Main() method to Execute class.

static void main(Args args)
{
    Test_DialogField tmpDialogField = new Test_DialogField();
    ;

    if (tmpDialogField.prompt())
        tmpDialogField.run();
}

Step 4: The dialogPostRun() method should override like below. This will allow calling to the event methods.

public void dialogPostRun(DialogRunbase tmpdialog)
{
    super(tmpdialog);
    tmpdialog.dialogForm().formRun().controlMethodOverload(true);
    tmpdialog.dialogForm().formRun().controlMethodOverloadObject(this);
}


Step 5: Add code to display dialog fields.

protected Object dialog(DialogRunbase tmpdialog, boolean forceOnClient)
{
    ;
    dialog = super(tmpdialog,forceOnClient);
    dialogCustId  = dialog.addFieldValue(typeid(CustAccount),"Customer", "Customer");
    dialoglName  = dialog.addFieldValue(typeid(Name),"Name", "Name");

    return dialog;
}

Step 6: When we have used Dialog field in the class, that Dialog field name in the System will appear with a different format. Its look like: fld<ID>_1. This ID value can be changed according to number of dialog filed which we have used. By using following step we can get exact Field ID & system Name.

·        Run the class which you created
·        Right Click on the Customer field & select “Setup”
·        You will get below form. I have coloured Dialog Filed System name by RED Colour. In my example System name of the Customer Dialog Field is Fld1_1.


This System Name we should use to write our “modified” method. Then it will call whenever a value of the dialog control with ID 1 is modified. In our case it is Customer ID field.

public boolean fld1_1_modified()
{
    FormStringControl control = dialog.formRun().controlCallingMethod();
    boolean isFieldModified;
    ;
    isFieldModified = control.modified();

    if(isFieldModified)
    {
    dialoglName.value(custTable::find(control.text()).Name);
    }
    return isFieldModified;
}

When you execute the class & select a customer Id, then above method will call & return the customer Name to other dialog box.

Hope you got an idea about overriding the Dialog Field methods in Dynamics AX... Enjoy in Dynamics AX World.