Wednesday, November 19, 2008

Connection from AX to an External Database

There are a few options. We can create an ODBC connection on a local machine or just to connect directly without creating ODBC record.


For exmaple, we want to check whether some records exist in an external table. We should create a OdbcConnection with appropriate LoginProperty and permit to execute a SQL statement by means of SqlStatementExecutePermission class. 



server boolean checkExternalDB()
{
//connection parameters
#define.ExternalTableName("CustTable")
#define.ExternalFieldName("AccountNum")
#define.ExternalSQLServerName("SRVAXSQL2005")
#define.ExternalSQLDBName("DAXdb401_Standard_DEV")
LoginProperty LP = new LoginProperty();
OdbcConnection myConnection;
SqlStatementExecutePermission permission;
Statement myStatement;
str sqlStmt = "";
ResultSet myResult;
boolean ret = true;
;

LP.setServer(#ExternalSQLServerName);
LP.setDatabase(#ExternalSQLDBName);
try
{
myConnection = new OdbcConnection(LP);
}
catch
{
info("Check connection parameters. "+funcName());
ret = checkFailed(strfmt("External DB Connection error in: %1"), #ExternalSQLDBName);
}

myStatement = myConnection.createStatement();
//anything you want to get from the external table
sqlStmt = "SELECT count (RecId) FROM "+#ExternalTableName+ " where "+#ExternalFieldName + " = '" + this.AccountNum+"'";

permission = new SqlStatementExecutePermission(sqlStmt);
permission.assert();

myResult = myStatement.executeQuery(sqlStmt);
while (MyResult.next())
{
if (MyResult.getInt(1) > 0)
{
//yes, records exist in the external table
ret = checkFailed(strfmt("@LBA53"+"\n"+funcName(), strfmt("[%1].[%2].[%3]", #ExternalSQLServerName, #ExternalSQLDBName, #ExternalTableName)));
break;
}
}

CodeAccessPermission::revertAssert();

return ret;
}

MS Outlook and CRM Tasks Synchronization Issue

Recently I found out an issue with synchronization of tasks between CRM module and MS Outlook in AX4.0SP2.

It looks like MS Outlook does not understand the command and causes the following error:

Method 'sort' in COM object of class '_Items' returned error code 0x80020009 (DISP_E_EXCEPTION) which means: Propriété « Start » inconnue.


I changed the synchronizeTasksOutlookToAxapta method of SmmOutlookSync_Task class in order to fix the problem like it was done in AX2009:

taskItemsCollection.sort('[Start]', false);

to

#define.startDateProperty('StartDate')
// Turn sort and include recurrences ON to get recurring tasks
taskItemsCollection.sort(#startDateProperty, false);

Friday, October 31, 2008

Debugging code on Business Connector

As MSDN our suggests, first, we should enable Debugger on the client, (do not be confused with versions! my previous link is correct for AX 4.0 and AX 2009 too, but this is only for AX 3.0)



Then, we must to enable the same on the Business Connector with Configuration Utility: (in my case I had to check both in order to debug my web service)


Now, you can add a breakpoint in your code.


Finally, you should run an instance of Debugger manually from the client's main menu because it does not start automatically as usually.


In conclusion I need to say that you should log in on your debugged application with the same user account which was used for the client and debugger sessions.



Lucky hunt for bugs!



Tuesday, October 21, 2008

Images on Form and Thumbnails in Grid

It is not a very complicated topic when it comes to show pictures on a form with Window control, but showing them in a grid caused some difficulties to me.

Here is the very simple project Images&ThumbnailsInGrid that will show you the way if are a little bit lost.


You can construct Image objects from the following file types:
  • Raster (bitmap) formats - .bmp, .gif, .jpg, .png, .tiff, and .exif
  • Vector formats - .emf and .wmf

By the way, do not forget about MSDN:

Friday, October 17, 2008

WCF and AIF in Dynamics 2009: Chatting with Michael Merz

WCF and AIF in Dynamics 2009: Chatting with Michael Merz

initParmDefault()

Just to remember: if you want to set up some value to a field on a dialog by default you should override standard method initParmDefault().

First time, AX takes it as a value, then it saves and restores the values the user input in the dialog form.

To see how it works just override this method for the class TestDemoRunBaseBacth as the following:
public void initParmDefault()
{
super();

i=11;
}
All values saved by Pack()method can be seen in Usage Data form: Tools\Options\Usage Data [Jobs - for classes]