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.


Wednesday, 15 December 2010

How to open TIF Image files in Dynamics AX

Today I’m going to discuss about one of another important feature in Dynamics AX. As well as the Other Programming languages, Axapta is supporting ActiveX object handling.
ActiveX control is a small program, which contains set of instruction & functions. Sometimes it’s called as add-ons.

Generally we can create an image viewer using this ActiveX object. In standard AX is coming with “Microsoft Web Browser” class for handling the Image Viewer ActiveX Control. But this viewer is accepting limited image file formats such as .JPG, GIF…

So I’m going to explain, powerful image viewer ActiveX control which supports a lot of popular image file extension, including TIFF, MNG, JNG,  BMP, GIF, ICO, JPEG,  PCX, PNG, PSD, WMF, WBMP, TGA, PGX, RAS, PNM.

That image Viewer ActiveX Control & Type Library is coming with Microsoft Office Package. That Is called “Microsoft Office Document Imaging 2003 (MODI)” model.

Step 1: When ActiveX control is placed in your PC, we have to get those files in to the Axapta using Wrapper Class. That can be done as follows,

Tools \ Development Tools \ Wizards \ COM Class Wrapper Wizard & go “Next”

Step 2:  select the “Microsoft Office Document Imaging 12.0 Type Library”. & click “Next”

Step 3: Enter an element mask. That will be appended to the front of the all elements generated by Wizard. In my example I’ve chosen “INDMODI”. & click “Next”.

Step 4: Create a new form & add ActiveX Control by right click on the design
In the ActiveX browser select the “Microsoft Office Document Imaging Viewer Control 12.0”.

Step 5: we need to specify the image path to open the file. For that add following code to the form


//Declaring Variable
public class FormRun extends ObjectRun
{
    INDMODIDocument    modiDocument;
}

//Initialize the Image path
public void init()
{
   ;
    super();
    activex.filename("Z:\\Images\\TestImage.gfd");
}


public void run()
{
    try
    {
        if(activeX.document())
        {
            modiDocument = new UKMODIDocument(activeX.document());
            super();
        }
    }
    catch (Exception::Error)
    {
        activeX.filename('');
    }
}


//Clear the Memory & Buffer
public void close()
{
    super();
    modiDocument.Close();
    activex.filename('');
}


Wednesday, 8 December 2010

Retrieve External Data using ODBC connection in Dynamics AX

When I’m flying in Dynamics AX world, I found most of the AX users are struggling to handle data from out source (External source such as MS-Access Database, Oracle Database, etc....).

In below I’m going to explain, how we can connect to the External Database using ODBC(Open Database Connectivity) Connection & retrieve data from that DB.

First we have to create a ODBC Datasource which has connected our Database. In my Example i have used DS as my Datasource name.

server static void GetShippingTrans(CustTable custTable)
{

     // Variable Declaration
LoginProperty lP;
OdbcConnection con;
Statement st;
ResultSet rS;
Str sqlS;
str databaseName = "Test"; 
MyShippingTrans trans;
SqlStatementExecutePermission sqlPermission;
;

// Initialize new Login Property
lP= new LoginProperty();

// Set DSN to the Login Property
lP.setDSN(DS);

//Set the correct DataBase to retrieve Data (May have more than one Database in that DSN)
lP.setDatabase(databaseName);

try
{

 //Create ODBC Connection by using Login Property
con= new OdbcConnection(lP);
st= con.createStatement();

//SQL Statement to select the Records from the Table
sqlS = StrFmt("SELECT %1, %2, %3 FROM Customer WHERE " +
"Customer.id = '%4',"Name", "DOB", "Height", custTable.CustId );

//Create a permission to execute SQL Statement
sqlPermission = new SQLStatementExecutePermission(sqlS);
sqlPermission.assert();

//Execute SQL Statement & retrieve the result set
            rS = st.executeQuery(sqlS);

while (rs.next())
{
            //Manipulate retrieved data.......
                     info(strFmt("Cust Name :%1    DOB : %2    Hieght : %3 "
                     ,rs.getString(1), rs.getDate(2), rs.getReal(3)));
}
CodeAccessPermission::revertAssert();
}
catch (Exception::Error)
{
            error(strFmt("Error accessing Customer database"));
}
}


I hope, now everyone has an idea about retrieving data from external data base & manipulating those fetched data.